Skip to content

Commit

Permalink
chore: review
Browse files Browse the repository at this point in the history
  • Loading branch information
kirillgroshkov committed Oct 3, 2023
1 parent 003baed commit f0f3ce0
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/pipeline/dbPipelineBackup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
pMap,
_passthroughMapper,
localTime,
UnixTimestampNumber,
StringMap,
} from '@naturalcycles/js-lib'
import {
NDJsonStats,
Expand Down Expand Up @@ -63,13 +65,16 @@ export interface DBPipelineBackupOptions extends TransformLogProgressOptions {
*/
limit?: number

/**
* If set - will do "incremental backup" (not full), only for entities that updated >= `sinceUpdated`
*/
sinceUpdated?: UnixTimestampNumber

/**
* Map for each table a `sinceUpdated` timestamp, or `undefined`.
* If set - will do "incremental backup" (not full), only for entities that updated >= `sinceUpdated` (on a per table basis)
*
* @default undefined
*/
sinceUpdatedByTable?: Map<string, number>
sinceUpdatedPerTable?: StringMap<UnixTimestampNumber>

/**
* Directory path to store dumped files. Will create `${tableName}.ndjson` (or .ndjson.gz if gzip=true) files.
Expand Down Expand Up @@ -101,7 +106,7 @@ export interface DBPipelineBackupOptions extends TransformLogProgressOptions {
* @default `{}`
* Default mappers will be "passthroughMapper" (pass all data as-is).
*/
mapperPerTable?: Record<string, AsyncMapper>
mapperPerTable?: StringMap<AsyncMapper>

/**
* You can alter default `transformMapOptions` here.
Expand Down Expand Up @@ -144,7 +149,6 @@ export async function dbPipelineBackup(opt: DBPipelineBackupOptions): Promise<ND
db,
concurrency = 16,
limit = 0,
sinceUpdatedByTable,
outputDirPath,
protectFromOverwrite = false,
zlibOptions,
Expand Down Expand Up @@ -172,7 +176,7 @@ export async function dbPipelineBackup(opt: DBPipelineBackupOptions): Promise<ND
await pMap(
tables,
async table => {
const sinceUpdated = sinceUpdatedByTable?.get(table)
const sinceUpdated = opt.sinceUpdatedPerTable?.[table] || opt.sinceUpdated

const sinceUpdatedStr = sinceUpdated
? ' since ' + grey(localTime(sinceUpdated).toPretty())
Expand Down

0 comments on commit f0f3ce0

Please sign in to comment.