rake-db 2.28.0 → 2.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +281 -308
- package/dist/index.js +978 -826
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +974 -823
- package/dist/index.mjs.map +1 -1
- package/dist/node-postgres.d.ts +2 -6
- package/dist/node-postgres.js +10 -36
- package/dist/node-postgres.js.map +1 -1
- package/dist/node-postgres.mjs +11 -36
- package/dist/node-postgres.mjs.map +1 -1
- package/dist/postgres-js.d.ts +3 -7
- package/dist/postgres-js.js +10 -36
- package/dist/postgres-js.js.map +1 -1
- package/dist/postgres-js.mjs +11 -36
- package/dist/postgres-js.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import * as pqb from 'pqb';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
interface CreateTableResult<Table extends string, Shape extends ColumnsShape> {
|
|
5
|
-
table: Db<Table, Shape>;
|
|
6
|
-
}
|
|
2
|
+
import { TableData, ColumnsShape, NoPrimaryKeyOption, MaybeArray, Column, RawSqlBase, RecordString, EnumColumn, EmptyObject, AdapterBase, DbResult, DefaultColumnTypes, DefaultSchemaConfig, QueryLogObject, TableDataFn, TableDataItem, DbDomainArg, ColumnSchemaConfig, raw, Db, MaybePromise, QueryLogOptions, QuerySchema, Query, SearchWeight, ColumnsByType, DbStructureDomainsMap } from 'pqb';
|
|
7
3
|
|
|
8
4
|
type RakeDbAst = RakeDbAst.Table | RakeDbAst.ChangeTable | RakeDbAst.RenameType | RakeDbAst.Schema | RakeDbAst.RenameSchema | RakeDbAst.Extension | RakeDbAst.Enum | RakeDbAst.EnumValues | RakeDbAst.RenameEnumValues | RakeDbAst.ChangeEnumValues | RakeDbAst.Domain | RakeDbAst.Collation | RakeDbAst.Constraint | RakeDbAst.RenameTableItem | RakeDbAst.View;
|
|
9
5
|
declare namespace RakeDbAst {
|
|
@@ -273,234 +269,6 @@ declare const tableChangeMethods: {
|
|
|
273
269
|
type TableChanger<CT> = MigrationColumnTypes<CT> & TableChangeMethods;
|
|
274
270
|
type TableChangeData = Record<string, RakeDbAst.ChangeTableItem.Column | RakeDbAst.ChangeTableItem.Rename | Change | SpecialChange | Column.Pick.Data>;
|
|
275
271
|
|
|
276
|
-
interface RakeDbCtx {
|
|
277
|
-
migrationsPromise?: Promise<MigrationsSet>;
|
|
278
|
-
}
|
|
279
|
-
declare const getSchemaAndTableFromName: (name: string) => [string | undefined, string];
|
|
280
|
-
declare const concatSchemaAndName: ({ schema, name, }: {
|
|
281
|
-
schema?: string;
|
|
282
|
-
name: string;
|
|
283
|
-
}, excludeCurrentSchema?: string) => string;
|
|
284
|
-
|
|
285
|
-
interface MigrationItemHasLoad {
|
|
286
|
-
path?: string;
|
|
287
|
-
/**
|
|
288
|
-
* Function that loads the migration content,
|
|
289
|
-
* can store lazy import of a migration file.
|
|
290
|
-
* Promise can return `{ default: x }` where `x` is a return of `change` or an array of such returns.
|
|
291
|
-
*/
|
|
292
|
-
load(): Promise<unknown>;
|
|
293
|
-
}
|
|
294
|
-
interface MigrationItem extends MigrationItemHasLoad {
|
|
295
|
-
path: string;
|
|
296
|
-
version: string;
|
|
297
|
-
}
|
|
298
|
-
interface MigrationsSet {
|
|
299
|
-
renameTo?: RakeDbRenameMigrations;
|
|
300
|
-
migrations: MigrationItem[];
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
interface CommandFn<SchemaConfig extends ColumnSchemaConfig, CT> {
|
|
304
|
-
(adapters: AdapterBase[], config: RakeDbConfig<SchemaConfig, CT>, args: string[]): void | Promise<void>;
|
|
305
|
-
}
|
|
306
|
-
interface PickBasePath {
|
|
307
|
-
basePath: string;
|
|
308
|
-
}
|
|
309
|
-
interface PickImport {
|
|
310
|
-
import(path: string): Promise<unknown>;
|
|
311
|
-
}
|
|
312
|
-
interface PickMigrationId {
|
|
313
|
-
migrationId: RakeDbMigrationId;
|
|
314
|
-
}
|
|
315
|
-
interface PickMigrations {
|
|
316
|
-
migrations?: ModuleExportsRecord;
|
|
317
|
-
}
|
|
318
|
-
interface PickMigrationsPath {
|
|
319
|
-
migrationsPath: string;
|
|
320
|
-
}
|
|
321
|
-
interface PickOptionalMigrationsPath {
|
|
322
|
-
migrationsPath?: string;
|
|
323
|
-
}
|
|
324
|
-
interface PickRenameMigrations {
|
|
325
|
-
renameMigrations?: RakeDbRenameMigrationsInput;
|
|
326
|
-
}
|
|
327
|
-
interface PickMigrationsTable {
|
|
328
|
-
schema?: string;
|
|
329
|
-
migrationsTable: string;
|
|
330
|
-
}
|
|
331
|
-
interface PickTransactionSetting {
|
|
332
|
-
transaction: 'single' | 'per-migration';
|
|
333
|
-
}
|
|
334
|
-
interface PickMigrationCallbacks {
|
|
335
|
-
beforeChange?: ChangeCallback$1;
|
|
336
|
-
afterChange?: ChangeCallback$1;
|
|
337
|
-
beforeMigrate?: MigrationCallback;
|
|
338
|
-
afterMigrate?: MigrationCallback;
|
|
339
|
-
beforeRollback?: MigrationCallback;
|
|
340
|
-
afterRollback?: MigrationCallback;
|
|
341
|
-
}
|
|
342
|
-
interface PickAfterChangeCommit {
|
|
343
|
-
afterChangeCommit?: ChangeCommitCallback;
|
|
344
|
-
}
|
|
345
|
-
interface PickForceDefaultExports {
|
|
346
|
-
forceDefaultExports?: boolean;
|
|
347
|
-
}
|
|
348
|
-
interface RakeDbBaseConfig<SchemaConfig extends ColumnSchemaConfig, CT = DefaultColumnTypes<DefaultSchemaConfig>> extends QueryLogOptions, PickImport, PickMigrationId, PickMigrationsPath, PickMigrations, PickRenameMigrations, PickMigrationsTable, PickMigrationCallbacks, PickForceDefaultExports, PickAfterChangeCommit {
|
|
349
|
-
schema?: string;
|
|
350
|
-
schemaConfig: SchemaConfig;
|
|
351
|
-
snakeCase: boolean;
|
|
352
|
-
language?: string;
|
|
353
|
-
commands: Record<string, CommandFn<SchemaConfig, CT>>;
|
|
354
|
-
noPrimaryKey?: NoPrimaryKeyOption;
|
|
355
|
-
baseTable?: RakeDbBaseTable<CT>;
|
|
356
|
-
}
|
|
357
|
-
interface RakeDbConfig<SchemaConfig extends ColumnSchemaConfig, CT = DefaultColumnTypes<DefaultSchemaConfig>> extends RakeDbBaseConfig<SchemaConfig, CT>, PickBasePath, PickTransactionSetting {
|
|
358
|
-
columnTypes: CT;
|
|
359
|
-
dbScript: string;
|
|
360
|
-
recurrentPath: string;
|
|
361
|
-
}
|
|
362
|
-
interface InputRakeDbConfigBase<SchemaConfig extends ColumnSchemaConfig, CT> extends QueryLogOptions, PickOptionalMigrationsPath {
|
|
363
|
-
columnTypes?: CT | ((t: DefaultColumnTypes<DefaultSchemaConfig>) => CT);
|
|
364
|
-
baseTable?: RakeDbBaseTable<CT>;
|
|
365
|
-
schemaConfig?: SchemaConfig;
|
|
366
|
-
basePath?: string;
|
|
367
|
-
dbScript?: string;
|
|
368
|
-
migrationId?: 'serial' | RakeDbMigrationId;
|
|
369
|
-
recurrentPath?: string;
|
|
370
|
-
migrationsTable?: string;
|
|
371
|
-
snakeCase?: boolean;
|
|
372
|
-
language?: string;
|
|
373
|
-
commands?: Record<string, (adapter: AdapterBase[], config: RakeDbConfig<SchemaConfig, CT>, args: string[]) => void | Promise<void>>;
|
|
374
|
-
noPrimaryKey?: NoPrimaryKeyOption;
|
|
375
|
-
forceDefaultExports?: boolean;
|
|
376
|
-
/**
|
|
377
|
-
* Is called once per db before migrating or rolling back a set of migrations.
|
|
378
|
-
*
|
|
379
|
-
* @param arg.db - query builder
|
|
380
|
-
* @param arg.up - whether it's migrating up or down
|
|
381
|
-
* @param arg.redo - whether it's migrating down and then up for `redo` command
|
|
382
|
-
* @param arg.migrations - array of executed (up or down) migrations
|
|
383
|
-
*/
|
|
384
|
-
beforeChange?: ChangeCallback$1;
|
|
385
|
-
/**
|
|
386
|
-
* Is called once per db after migrating or rolling back a set of migrations.
|
|
387
|
-
* Runs inside the same transaction as migrations,
|
|
388
|
-
* for running after commit use {@link afterChangeCommit}.
|
|
389
|
-
*
|
|
390
|
-
* @param arg.db - query builder
|
|
391
|
-
* @param arg.up - whether it's migrating up or down
|
|
392
|
-
* @param arg.redo - whether it's migrating down and then up for `redo` command
|
|
393
|
-
* @param arg.migrations - array of executed (up or down) migrations
|
|
394
|
-
*/
|
|
395
|
-
afterChange?: ChangeCallback$1;
|
|
396
|
-
/**
|
|
397
|
-
* Is called once per db after migrating or rolling back a set of migrations.
|
|
398
|
-
* Runs **after** committing migrations transaction.
|
|
399
|
-
*
|
|
400
|
-
* @param arg.options - database connection options
|
|
401
|
-
* @param arg.up - whether it's migrating up or down
|
|
402
|
-
* @param arg.migrations - array of executed (up or down) migrations
|
|
403
|
-
*/
|
|
404
|
-
afterChangeCommit?: ChangeCommitCallback;
|
|
405
|
-
/**
|
|
406
|
-
* Is called once per db before migrating (up) a set of migrations.
|
|
407
|
-
*
|
|
408
|
-
* @param arg.db - query builder
|
|
409
|
-
* @param arg.migrations - applied migrations
|
|
410
|
-
*/
|
|
411
|
-
beforeMigrate?: MigrationCallback;
|
|
412
|
-
/**
|
|
413
|
-
* Is called once per db after migrating (up) a set of migrations.
|
|
414
|
-
*
|
|
415
|
-
* @param arg.db - query builder
|
|
416
|
-
* @param arg.migrations - applied migrations
|
|
417
|
-
*/
|
|
418
|
-
afterMigrate?: MigrationCallback;
|
|
419
|
-
/**
|
|
420
|
-
* Is called once per db before rolling back a set of migrations.
|
|
421
|
-
*
|
|
422
|
-
* @param arg.db - query builder
|
|
423
|
-
* @param arg.migrations - rolled back migrations
|
|
424
|
-
*/
|
|
425
|
-
beforeRollback?: MigrationCallback;
|
|
426
|
-
/**
|
|
427
|
-
* Is called once per db before rolling back a set of migrations.
|
|
428
|
-
*
|
|
429
|
-
* @param arg.db - query builder
|
|
430
|
-
* @param arg.migrations - rolled back migrations
|
|
431
|
-
*/
|
|
432
|
-
afterRollback?: MigrationCallback;
|
|
433
|
-
}
|
|
434
|
-
interface InputRakeDbConfigFileBased<SchemaConfig extends ColumnSchemaConfig, CT> extends InputRakeDbConfigBase<SchemaConfig, CT> {
|
|
435
|
-
/**
|
|
436
|
-
* It may look odd, but it's required for `tsx` and other bundlers to have such `import` config specified explicitly.
|
|
437
|
-
*/
|
|
438
|
-
import(path: string): Promise<unknown>;
|
|
439
|
-
}
|
|
440
|
-
interface InputRakeDbConfigCodeBased<SchemaConfig extends ColumnSchemaConfig, CT> extends InputRakeDbConfigBase<SchemaConfig, CT> {
|
|
441
|
-
/**
|
|
442
|
-
* To specify array of migrations explicitly, without loading them from files.
|
|
443
|
-
*/
|
|
444
|
-
migrations: ModuleExportsRecord;
|
|
445
|
-
renameMigrations?: RakeDbRenameMigrationsInput;
|
|
446
|
-
/**
|
|
447
|
-
* It may look odd, but it's required for `tsx` and other bundlers to have such `import` config specified explicitly.
|
|
448
|
-
*/
|
|
449
|
-
import?(path: string): Promise<unknown>;
|
|
450
|
-
}
|
|
451
|
-
type InputRakeDbConfig<SchemaConfig extends ColumnSchemaConfig, CT> = InputRakeDbConfigFileBased<SchemaConfig, CT> | InputRakeDbConfigCodeBased<SchemaConfig, CT>;
|
|
452
|
-
interface ChangeCallback$1 {
|
|
453
|
-
(arg: {
|
|
454
|
-
db: DbResult<unknown>;
|
|
455
|
-
up: boolean;
|
|
456
|
-
redo: boolean;
|
|
457
|
-
migrations: MigrationItem[];
|
|
458
|
-
}): void | Promise<void>;
|
|
459
|
-
}
|
|
460
|
-
interface ChangeCommitCallback {
|
|
461
|
-
(arg: {
|
|
462
|
-
adapter: AdapterBase;
|
|
463
|
-
up: boolean;
|
|
464
|
-
migrations: MigrationItem[];
|
|
465
|
-
}): void | Promise<void>;
|
|
466
|
-
}
|
|
467
|
-
interface MigrationCallback {
|
|
468
|
-
(arg: {
|
|
469
|
-
db: DbResult<unknown>;
|
|
470
|
-
migrations: MigrationItem[];
|
|
471
|
-
}): void | Promise<void>;
|
|
472
|
-
}
|
|
473
|
-
type AnyRakeDbConfig = RakeDbConfig<any, any>;
|
|
474
|
-
interface RakeDbBaseTable<CT> {
|
|
475
|
-
exportAs: string;
|
|
476
|
-
getFilePath(): string;
|
|
477
|
-
nowSQL?: string;
|
|
478
|
-
new (): {
|
|
479
|
-
types: CT;
|
|
480
|
-
snakeCase?: boolean;
|
|
481
|
-
language?: string;
|
|
482
|
-
};
|
|
483
|
-
}
|
|
484
|
-
interface ModuleExportsRecord {
|
|
485
|
-
[K: string]: () => Promise<unknown>;
|
|
486
|
-
}
|
|
487
|
-
type RakeDbMigrationId = 'timestamp' | {
|
|
488
|
-
serial: number;
|
|
489
|
-
};
|
|
490
|
-
interface RakeDbRenameMigrationsMap {
|
|
491
|
-
[K: string]: number;
|
|
492
|
-
}
|
|
493
|
-
interface RakeDbRenameMigrations {
|
|
494
|
-
to: RakeDbMigrationId;
|
|
495
|
-
map(): MaybePromise<RakeDbRenameMigrationsMap>;
|
|
496
|
-
}
|
|
497
|
-
interface RakeDbRenameMigrationsInput {
|
|
498
|
-
to: RakeDbMigrationId;
|
|
499
|
-
map: RakeDbRenameMigrationsMap;
|
|
500
|
-
}
|
|
501
|
-
declare const migrationConfigDefaults: RakeDbBaseConfig<ColumnSchemaConfig>;
|
|
502
|
-
declare const processRakeDbConfig: <SchemaConfig extends ColumnSchemaConfig<pqb.Column.Pick.Data>, CT>(config: InputRakeDbConfig<SchemaConfig, CT>, args?: string[]) => RakeDbConfig<SchemaConfig, CT>;
|
|
503
|
-
|
|
504
272
|
type DropMode = 'CASCADE' | 'RESTRICT';
|
|
505
273
|
type TableOptions = {
|
|
506
274
|
createIfNotExists?: boolean;
|
|
@@ -530,9 +298,6 @@ type SilentQueries = {
|
|
|
530
298
|
type DbMigration<CT> = DbResult<CT> & Migration<CT> & {
|
|
531
299
|
adapter: SilentQueries;
|
|
532
300
|
};
|
|
533
|
-
interface CreateMigrationInterfaceConfig<CT> extends QueryLogOptions {
|
|
534
|
-
columnTypes: CT;
|
|
535
|
-
}
|
|
536
301
|
/**
|
|
537
302
|
* Creates a new `db` instance that is an instance of `pqb` with mixed in migration methods from the `Migration` class.
|
|
538
303
|
* It overrides `query` and `array` db adapter methods to intercept SQL for the logging.
|
|
@@ -541,13 +306,13 @@ interface CreateMigrationInterfaceConfig<CT> extends QueryLogOptions {
|
|
|
541
306
|
* @param up - migrate or rollback
|
|
542
307
|
* @param config - config of `rakeDb`
|
|
543
308
|
*/
|
|
544
|
-
declare const createMigrationInterface:
|
|
309
|
+
declare const createMigrationInterface: (tx: AdapterBase, up: boolean, config: Pick<RakeDbConfig, 'log' | 'logger' | 'columnTypes'>) => DbMigration<DefaultColumnTypes<DefaultSchemaConfig>>;
|
|
545
310
|
type MigrationAdapter = AdapterBase;
|
|
546
|
-
declare class Migration<CT> {
|
|
311
|
+
declare class Migration<CT = unknown> {
|
|
547
312
|
adapter: MigrationAdapter;
|
|
548
313
|
log?: QueryLogObject;
|
|
549
314
|
up: boolean;
|
|
550
|
-
options: RakeDbConfig
|
|
315
|
+
options: RakeDbConfig;
|
|
551
316
|
columnTypes: CT;
|
|
552
317
|
/**
|
|
553
318
|
* `createTable` accepts a string for a table name, optional options, and a callback to specify columns.
|
|
@@ -1452,35 +1217,242 @@ interface AddEnumValueOptions {
|
|
|
1452
1217
|
after?: string;
|
|
1453
1218
|
}
|
|
1454
1219
|
|
|
1455
|
-
interface
|
|
1456
|
-
|
|
1457
|
-
config: RakeDbConfig<ColumnSchemaConfig, unknown>;
|
|
1220
|
+
interface CreateTableResult<Table extends string, Shape extends ColumnsShape> {
|
|
1221
|
+
table: Db<Table, Shape>;
|
|
1458
1222
|
}
|
|
1459
|
-
type ChangeCallback<CT> = (db: DbMigration<CT>, up: boolean) => Promise<void>;
|
|
1460
1223
|
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1224
|
+
interface RakeDbCtx {
|
|
1225
|
+
migrationsPromise?: Promise<MigrationsSet>;
|
|
1226
|
+
}
|
|
1227
|
+
declare const getSchemaAndTableFromName: (config: Pick<RakeDbConfig, 'schema'>, name: string) => [string | undefined, string];
|
|
1228
|
+
declare const concatSchemaAndName: ({ schema, name, }: {
|
|
1229
|
+
schema?: string;
|
|
1230
|
+
name: string;
|
|
1231
|
+
}, excludeCurrentSchema?: string) => string;
|
|
1232
|
+
|
|
1233
|
+
interface MigrationItemHasLoad {
|
|
1234
|
+
path?: string;
|
|
1235
|
+
/**
|
|
1236
|
+
* Function that loads the migration content,
|
|
1237
|
+
* can store lazy import of a migration file.
|
|
1238
|
+
* Promise can return `{ default: x }` where `x` is a return of `change` or an array of such returns.
|
|
1239
|
+
*/
|
|
1240
|
+
load(): MaybePromise<unknown>;
|
|
1241
|
+
}
|
|
1242
|
+
interface MigrationItem extends MigrationItemHasLoad {
|
|
1243
|
+
path: string;
|
|
1244
|
+
version: string;
|
|
1245
|
+
}
|
|
1246
|
+
interface MigrationsSet {
|
|
1247
|
+
renameTo?: RakeDbRenameMigrations;
|
|
1248
|
+
migrations: MigrationItem[];
|
|
1249
|
+
}
|
|
1250
|
+
|
|
1251
|
+
interface RakeDbCliConfigInputBase<SchemaConfig extends ColumnSchemaConfig, CT = DefaultColumnTypes<DefaultSchemaConfig>> extends QueryLogOptions {
|
|
1252
|
+
columnTypes?: CT | ((t: DefaultColumnTypes<DefaultSchemaConfig>) => CT);
|
|
1253
|
+
baseTable?: RakeDbBaseTable<CT>;
|
|
1254
|
+
schemaConfig?: SchemaConfig;
|
|
1255
|
+
basePath?: string;
|
|
1256
|
+
dbScript?: string;
|
|
1257
|
+
migrationId?: 'serial' | RakeDbMigrationId;
|
|
1258
|
+
recurrentPath?: string;
|
|
1259
|
+
migrationsTable?: string;
|
|
1260
|
+
snakeCase?: boolean;
|
|
1261
|
+
language?: string;
|
|
1262
|
+
commands?: {
|
|
1263
|
+
[commandName: string]: RakeDbCommandFn | RakeDbCommand;
|
|
1264
|
+
};
|
|
1265
|
+
noPrimaryKey?: NoPrimaryKeyOption;
|
|
1266
|
+
forceDefaultExports?: boolean;
|
|
1267
|
+
/**
|
|
1268
|
+
* Is called once per db before migrating or rolling back a set of migrations.
|
|
1269
|
+
*
|
|
1270
|
+
* @param arg.db - query builder
|
|
1271
|
+
* @param arg.up - whether it's migrating up or down
|
|
1272
|
+
* @param arg.redo - whether it's migrating down and then up for `redo` command
|
|
1273
|
+
* @param arg.migrations - array of executed (up or down) migrations
|
|
1274
|
+
*/
|
|
1275
|
+
beforeChange?: ChangeCallback$1;
|
|
1276
|
+
/**
|
|
1277
|
+
* Is called once per db after migrating or rolling back a set of migrations.
|
|
1278
|
+
* Runs inside the same transaction as migrations,
|
|
1279
|
+
* for running after commit use {@link afterChangeCommit}.
|
|
1280
|
+
*
|
|
1281
|
+
* @param arg.db - query builder
|
|
1282
|
+
* @param arg.up - whether it's migrating up or down
|
|
1283
|
+
* @param arg.redo - whether it's migrating down and then up for `redo` command
|
|
1284
|
+
* @param arg.migrations - array of executed (up or down) migrations
|
|
1285
|
+
*/
|
|
1286
|
+
afterChange?: ChangeCallback$1;
|
|
1466
1287
|
/**
|
|
1467
|
-
*
|
|
1468
|
-
*
|
|
1288
|
+
* Is called once per db after migrating or rolling back a set of migrations.
|
|
1289
|
+
* Runs **after** committing migrations transaction.
|
|
1469
1290
|
*
|
|
1470
|
-
* @param options -
|
|
1471
|
-
* @param
|
|
1472
|
-
* @
|
|
1291
|
+
* @param arg.options - database connection options
|
|
1292
|
+
* @param arg.up - whether it's migrating up or down
|
|
1293
|
+
* @param arg.migrations - array of executed (up or down) migrations
|
|
1473
1294
|
*/
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1295
|
+
afterChangeCommit?: ChangeCommitCallback;
|
|
1296
|
+
/**
|
|
1297
|
+
* Is called once per db before migrating (up) a set of migrations.
|
|
1298
|
+
*
|
|
1299
|
+
* @param arg.db - query builder
|
|
1300
|
+
* @param arg.migrations - applied migrations
|
|
1301
|
+
*/
|
|
1302
|
+
beforeMigrate?: MigrationCallback;
|
|
1303
|
+
/**
|
|
1304
|
+
* Is called once per db after migrating (up) a set of migrations.
|
|
1305
|
+
*
|
|
1306
|
+
* @param arg.db - query builder
|
|
1307
|
+
* @param arg.migrations - applied migrations
|
|
1308
|
+
*/
|
|
1309
|
+
afterMigrate?: MigrationCallback;
|
|
1310
|
+
/**
|
|
1311
|
+
* Is called once per db before rolling back a set of migrations.
|
|
1312
|
+
*
|
|
1313
|
+
* @param arg.db - query builder
|
|
1314
|
+
* @param arg.migrations - rolled back migrations
|
|
1315
|
+
*/
|
|
1316
|
+
beforeRollback?: MigrationCallback;
|
|
1317
|
+
/**
|
|
1318
|
+
* Is called once per db before rolling back a set of migrations.
|
|
1319
|
+
*
|
|
1320
|
+
* @param arg.db - query builder
|
|
1321
|
+
* @param arg.migrations - rolled back migrations
|
|
1322
|
+
*/
|
|
1323
|
+
afterRollback?: MigrationCallback;
|
|
1324
|
+
/**
|
|
1325
|
+
* It may look odd, but it's required for `tsx` and other bundlers to have such `import` config specified explicitly.
|
|
1326
|
+
*/
|
|
1327
|
+
import?(path: string): Promise<unknown>;
|
|
1328
|
+
}
|
|
1329
|
+
interface RakeDbCliConfigInputFileBased<SchemaConfig extends ColumnSchemaConfig, CT = DefaultColumnTypes<DefaultSchemaConfig>> extends RakeDbCliConfigInputBase<SchemaConfig, CT> {
|
|
1330
|
+
migrationsPath?: string;
|
|
1331
|
+
/**
|
|
1332
|
+
* required for `tsx` and other bundlers to have such `import` config specified explicitly.
|
|
1333
|
+
*/
|
|
1334
|
+
import(path: string): Promise<unknown>;
|
|
1335
|
+
}
|
|
1336
|
+
interface RakeDbCliConfigInputCodeBased<SchemaConfig extends ColumnSchemaConfig, CT = DefaultColumnTypes<DefaultSchemaConfig>> extends RakeDbCliConfigInputBase<SchemaConfig, CT> {
|
|
1337
|
+
/**
|
|
1338
|
+
* To specify array of migrations explicitly, without loading them from files.
|
|
1339
|
+
*/
|
|
1340
|
+
migrations: ModuleExportsRecord;
|
|
1341
|
+
renameMigrations?: RakeDbRenameMigrationsInput;
|
|
1342
|
+
}
|
|
1343
|
+
type RakeDbCliConfigInput<SchemaConfig extends ColumnSchemaConfig, CT = DefaultColumnTypes<DefaultSchemaConfig>> = RakeDbCliConfigInputFileBased<SchemaConfig, CT> | RakeDbCliConfigInputCodeBased<SchemaConfig, CT>;
|
|
1344
|
+
interface RakeDbConfig<ColumnTypes = unknown> extends QueryLogOptions {
|
|
1345
|
+
/**
|
|
1346
|
+
* Set by makeRakeDbConfig to distinguish between the user-provided initial config from the processed one.
|
|
1347
|
+
*/
|
|
1348
|
+
__rakeDbConfig: true;
|
|
1349
|
+
migrationsTable: string;
|
|
1350
|
+
/**
|
|
1351
|
+
* by default, all the migrated tables and the special table for tracking migrations are created in `public`.
|
|
1352
|
+
* set this `schema` setting to use create everything in this schema instead.
|
|
1353
|
+
*/
|
|
1354
|
+
schema?: QuerySchema;
|
|
1355
|
+
recurrentPath?: string;
|
|
1356
|
+
columnTypes: ColumnTypes;
|
|
1357
|
+
beforeChange?: ChangeCallback$1;
|
|
1358
|
+
afterChange?: ChangeCallback$1;
|
|
1359
|
+
beforeMigrate?: MigrationCallback;
|
|
1360
|
+
afterMigrate?: MigrationCallback;
|
|
1361
|
+
beforeRollback?: MigrationCallback;
|
|
1362
|
+
afterRollback?: MigrationCallback;
|
|
1363
|
+
migrationId: RakeDbMigrationId;
|
|
1364
|
+
forceDefaultExports?: boolean;
|
|
1365
|
+
afterChangeCommit?: ChangeCommitCallback;
|
|
1366
|
+
basePath: string;
|
|
1367
|
+
import(path: string): Promise<unknown>;
|
|
1368
|
+
migrationsPath: string;
|
|
1369
|
+
transaction: 'single' | 'per-migration';
|
|
1370
|
+
snakeCase?: boolean;
|
|
1371
|
+
schemaConfig: ColumnSchemaConfig;
|
|
1372
|
+
migrations?: ModuleExportsRecord;
|
|
1373
|
+
dbScript: string;
|
|
1374
|
+
renameMigrations?: RakeDbRenameMigrationsInput;
|
|
1375
|
+
language?: string;
|
|
1376
|
+
noPrimaryKey?: NoPrimaryKeyOption;
|
|
1377
|
+
baseTable?: RakeDbBaseTable<unknown>;
|
|
1378
|
+
commands: RakeDbCommands;
|
|
1379
|
+
}
|
|
1380
|
+
declare const migrationConfigDefaults: {
|
|
1381
|
+
schemaConfig: DefaultSchemaConfig;
|
|
1382
|
+
migrationsPath: string;
|
|
1383
|
+
migrationId: {
|
|
1384
|
+
serial: number;
|
|
1385
|
+
};
|
|
1386
|
+
migrationsTable: string;
|
|
1387
|
+
snakeCase: boolean;
|
|
1388
|
+
commands: {};
|
|
1389
|
+
log: boolean;
|
|
1390
|
+
logger: Console;
|
|
1391
|
+
import(): never;
|
|
1392
|
+
};
|
|
1393
|
+
interface RakeDbCommandFn {
|
|
1394
|
+
(adapters: AdapterBase[], config: RakeDbConfig, args: string[]): MaybePromise<unknown>;
|
|
1395
|
+
}
|
|
1396
|
+
interface RakeDbCommand {
|
|
1397
|
+
run: RakeDbCommandFn;
|
|
1398
|
+
help?: string;
|
|
1399
|
+
helpArguments?: RecordString;
|
|
1400
|
+
helpAfter?: string;
|
|
1401
|
+
}
|
|
1402
|
+
interface RakeDbCommands {
|
|
1403
|
+
[K: string]: RakeDbCommand;
|
|
1404
|
+
}
|
|
1405
|
+
interface ChangeCallback$1 {
|
|
1406
|
+
(arg: {
|
|
1407
|
+
db: DbResult<unknown>;
|
|
1408
|
+
up: boolean;
|
|
1409
|
+
redo: boolean;
|
|
1410
|
+
migrations: MigrationItem[];
|
|
1411
|
+
}): void | Promise<void>;
|
|
1412
|
+
}
|
|
1413
|
+
interface ChangeCommitCallback {
|
|
1414
|
+
(arg: {
|
|
1415
|
+
adapter: AdapterBase;
|
|
1416
|
+
up: boolean;
|
|
1417
|
+
migrations: MigrationItem[];
|
|
1418
|
+
}): void | Promise<void>;
|
|
1419
|
+
}
|
|
1420
|
+
interface MigrationCallback {
|
|
1421
|
+
(arg: {
|
|
1422
|
+
db: DbResult<unknown>;
|
|
1423
|
+
migrations: MigrationItem[];
|
|
1424
|
+
}): void | Promise<void>;
|
|
1425
|
+
}
|
|
1426
|
+
interface RakeDbBaseTable<CT> {
|
|
1427
|
+
exportAs: string;
|
|
1428
|
+
getFilePath(): string;
|
|
1429
|
+
nowSQL?: string;
|
|
1430
|
+
new (): {
|
|
1431
|
+
types: CT;
|
|
1432
|
+
snakeCase?: boolean;
|
|
1433
|
+
language?: string;
|
|
1477
1434
|
};
|
|
1478
1435
|
}
|
|
1479
|
-
interface
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1436
|
+
interface ModuleExportsRecord {
|
|
1437
|
+
[fileName: string]: () => Promise<unknown>;
|
|
1438
|
+
}
|
|
1439
|
+
type RakeDbMigrationId = 'timestamp' | {
|
|
1440
|
+
serial: number;
|
|
1441
|
+
};
|
|
1442
|
+
interface RakeDbRenameMigrationsMap {
|
|
1443
|
+
[K: string]: number;
|
|
1444
|
+
}
|
|
1445
|
+
interface RakeDbRenameMigrations {
|
|
1446
|
+
to: RakeDbMigrationId;
|
|
1447
|
+
map(): MaybePromise<RakeDbRenameMigrationsMap>;
|
|
1448
|
+
}
|
|
1449
|
+
interface RakeDbRenameMigrationsInput {
|
|
1450
|
+
to: RakeDbMigrationId;
|
|
1451
|
+
map: RakeDbRenameMigrationsMap;
|
|
1483
1452
|
}
|
|
1453
|
+
declare const incrementIntermediateCaller: () => void;
|
|
1454
|
+
declare const makeRakeDbConfig: <ColumnTypes>(config: RakeDbCliConfigInput<ColumnSchemaConfig, ColumnTypes>, args?: string[]) => RakeDbConfig<ColumnTypes>;
|
|
1455
|
+
|
|
1484
1456
|
/**
|
|
1485
1457
|
* Function to use in migrations to wrap database changes
|
|
1486
1458
|
* Saves the given callback to an internal queue,
|
|
@@ -1489,18 +1461,23 @@ interface RakeDbResult {
|
|
|
1489
1461
|
interface RakeDbChangeFn<CT> {
|
|
1490
1462
|
(fn: ChangeCallback<CT>): MigrationChange;
|
|
1491
1463
|
}
|
|
1492
|
-
interface
|
|
1493
|
-
|
|
1464
|
+
interface MigrationChange {
|
|
1465
|
+
fn: ChangeCallback<unknown>;
|
|
1466
|
+
config: RakeDbConfig;
|
|
1494
1467
|
}
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1468
|
+
type ChangeCallback<CT> = (db: DbMigration<CT>, up: boolean) => Promise<void>;
|
|
1469
|
+
|
|
1470
|
+
interface RakeDbCliResult<ColumnTypes, Options> {
|
|
1471
|
+
change: RakeDbChangeFn<ColumnTypes>;
|
|
1472
|
+
run(options: Options, args?: string[]): Promise<void>;
|
|
1473
|
+
}
|
|
1474
|
+
interface RakeDbFn<Options> {
|
|
1475
|
+
<SchemaConfig extends ColumnSchemaConfig, ColumnTypes = DefaultColumnTypes<DefaultSchemaConfig>>(config: RakeDbCliConfigInput<SchemaConfig, ColumnTypes> | RakeDbConfig<ColumnTypes>, args?: string[]): RakeDbCliResult<ColumnTypes, Options>;
|
|
1476
|
+
run<SchemaConfig extends ColumnSchemaConfig, ColumnTypes = DefaultColumnTypes<DefaultSchemaConfig>>(options: Options, config: RakeDbCliConfigInput<SchemaConfig, ColumnTypes> | RakeDbConfig<ColumnTypes>, args?: string[]): RakeDbChangeFn<ColumnTypes>;
|
|
1477
|
+
}
|
|
1478
|
+
declare const rakeDbCliWithAdapter: RakeDbFn<MaybeArray<AdapterBase>>;
|
|
1479
|
+
declare const setRakeDbCliRunFn: <T>(rakeDbCli: RakeDbFn<T>, mapper: (options: T) => unknown) => void;
|
|
1480
|
+
declare const rakeDbCommands: RakeDbCommands;
|
|
1504
1481
|
|
|
1505
1482
|
declare const encodeColumnDefault: (def: unknown, values: unknown[], column?: Column.Pick.Data) => string | null;
|
|
1506
1483
|
declare const getConstraintName: (table: string, constraint: {
|
|
@@ -1519,7 +1496,10 @@ interface GetIndexOrExcludeName {
|
|
|
1519
1496
|
}
|
|
1520
1497
|
declare const getIndexName: GetIndexOrExcludeName;
|
|
1521
1498
|
declare const getExcludeName: GetIndexOrExcludeName;
|
|
1522
|
-
declare const getMigrationsSchemaAndTable: (config:
|
|
1499
|
+
declare const getMigrationsSchemaAndTable: (config: {
|
|
1500
|
+
schema?: QuerySchema;
|
|
1501
|
+
migrationsTable: string;
|
|
1502
|
+
}) => {
|
|
1523
1503
|
schema?: string;
|
|
1524
1504
|
table: string;
|
|
1525
1505
|
};
|
|
@@ -1531,18 +1511,22 @@ declare const promptSelect: ({ message, options, active, inactive, }: {
|
|
|
1531
1511
|
inactive?: (s: string) => string;
|
|
1532
1512
|
}) => Promise<number>;
|
|
1533
1513
|
|
|
1534
|
-
declare const saveMigratedVersion: (db: SilentQueries, version: string, name: string, config:
|
|
1514
|
+
declare const saveMigratedVersion: (db: SilentQueries, version: string, name: string, config: Pick<RakeDbConfig, 'migrationsTable'>) => Promise<void>;
|
|
1535
1515
|
|
|
1536
|
-
interface
|
|
1516
|
+
interface OrmParam {
|
|
1517
|
+
$qb: Query;
|
|
1518
|
+
$adapter: AdapterBase;
|
|
1537
1519
|
}
|
|
1520
|
+
type DbParam = OrmParam | AdapterBase;
|
|
1521
|
+
|
|
1538
1522
|
interface MigrateFnParams {
|
|
1539
1523
|
ctx?: RakeDbCtx;
|
|
1540
|
-
adapter: AdapterBase;
|
|
1541
|
-
config: MigrateFnConfig;
|
|
1542
1524
|
count?: number;
|
|
1543
1525
|
force?: boolean;
|
|
1544
1526
|
}
|
|
1545
|
-
|
|
1527
|
+
interface MigrateFn {
|
|
1528
|
+
(db: DbParam, config: RakeDbConfig, params?: MigrateFnParams): Promise<void>;
|
|
1529
|
+
}
|
|
1546
1530
|
/**
|
|
1547
1531
|
* Will run all pending yet migrations, sequentially in order,
|
|
1548
1532
|
* will apply `change` functions top-to-bottom.
|
|
@@ -1553,9 +1537,20 @@ type MigrateFn = (params: MigrateFnParams) => Promise<void>;
|
|
|
1553
1537
|
*/
|
|
1554
1538
|
declare const migrate: MigrateFn;
|
|
1555
1539
|
declare const migrateAndClose: MigrateFn;
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1540
|
+
declare const runMigration: (db: DbParam, migration: () => MaybePromise<unknown>) => Promise<void>;
|
|
1541
|
+
/**
|
|
1542
|
+
* Will roll back one latest applied migration,
|
|
1543
|
+
* will apply `change` functions bottom-to-top.
|
|
1544
|
+
*
|
|
1545
|
+
* Takes the same options as {@link migrate}.
|
|
1546
|
+
*/
|
|
1547
|
+
declare const rollback: MigrateFn;
|
|
1548
|
+
/**
|
|
1549
|
+
* Calls {@link rollback} and then {@link migrate}.
|
|
1550
|
+
*
|
|
1551
|
+
* Takes the same options as {@link migrate}.
|
|
1552
|
+
*/
|
|
1553
|
+
declare const redo: MigrateFn;
|
|
1559
1554
|
|
|
1560
1555
|
declare namespace DbStructure {
|
|
1561
1556
|
interface TableNameAndSchemaName {
|
|
@@ -1721,7 +1716,7 @@ interface IntrospectedStructure {
|
|
|
1721
1716
|
}
|
|
1722
1717
|
declare function introspectDbSchema(db: AdapterBase): Promise<IntrospectedStructure>;
|
|
1723
1718
|
|
|
1724
|
-
declare const astToMigration: (currentSchema: string, config:
|
|
1719
|
+
declare const astToMigration: (currentSchema: string, config: RakeDbConfig, asts: RakeDbAst[]) => string | undefined;
|
|
1725
1720
|
|
|
1726
1721
|
interface StructureToAstCtx {
|
|
1727
1722
|
snakeCase?: boolean;
|
|
@@ -1736,8 +1731,8 @@ interface StructureToAstTableData {
|
|
|
1736
1731
|
excludes: DbStructure.Exclude[];
|
|
1737
1732
|
constraints: DbStructure.Constraint[];
|
|
1738
1733
|
}
|
|
1739
|
-
declare const makeStructureToAstCtx: (config:
|
|
1740
|
-
declare const structureToAst: (ctx: StructureToAstCtx, adapter: AdapterBase, config:
|
|
1734
|
+
declare const makeStructureToAstCtx: (config: Pick<RakeDbConfig, 'snakeCase' | 'schemaConfig'>, currentSchema: string) => StructureToAstCtx;
|
|
1735
|
+
declare const structureToAst: (ctx: StructureToAstCtx, adapter: AdapterBase, config: Pick<RakeDbConfig, 'schema' | 'migrationsTable'>) => Promise<RakeDbAst[]>;
|
|
1741
1736
|
declare const makeDomainsMap: (ctx: StructureToAstCtx, data: IntrospectedStructure) => DbStructureDomainsMap;
|
|
1742
1737
|
declare const instantiateDbColumn: (ctx: StructureToAstCtx, data: IntrospectedStructure, domains: DbStructureDomainsMap, dbColumn: DbStructure.Column) => Column<pqb.ColumnTypeSchemaArg, unknown, any, any, unknown, unknown, any, unknown, any>;
|
|
1743
1738
|
declare const tableToAst: (ctx: StructureToAstCtx, data: IntrospectedStructure, table: DbStructure.Table, action: 'create' | 'drop', domains: DbStructureDomainsMap) => RakeDbAst.Table;
|
|
@@ -1748,32 +1743,10 @@ interface ColumnChecks {
|
|
|
1748
1743
|
declare const getDbTableColumnsChecks: (tableData: StructureToAstTableData) => ColumnChecks;
|
|
1749
1744
|
declare const dbColumnToAst: (ctx: StructureToAstCtx, data: IntrospectedStructure, domains: DbStructureDomainsMap, tableName: string, item: DbStructure.Column, table?: DbStructure.Table, tableData?: StructureToAstTableData, checks?: ColumnChecks) => [key: string, column: Column];
|
|
1750
1745
|
|
|
1751
|
-
declare const writeMigrationFile: (config:
|
|
1752
|
-
declare const makeFileVersion: (ctx: RakeDbCtx, config:
|
|
1753
|
-
|
|
1754
|
-
interface OrmParam {
|
|
1755
|
-
$qb: Query;
|
|
1756
|
-
}
|
|
1757
|
-
type UnknownPromiseFns = (() => Promise<unknown>)[];
|
|
1758
|
-
declare const migrateFiles: (db: OrmParam, files: UnknownPromiseFns) => Promise<void>;
|
|
1759
|
-
declare const makeMigrateAdapter: (config?: Partial<MigrateFnConfig>) => ((adapter: AdapterBase, params?: {
|
|
1760
|
-
count?: number;
|
|
1761
|
-
force?: boolean;
|
|
1762
|
-
}) => Promise<void>);
|
|
1746
|
+
declare const writeMigrationFile: (config: Pick<RakeDbConfig, 'migrationsPath' | 'basePath' | 'dbScript' | 'logger'>, version: string, name: string, migrationCode: string) => Promise<void>;
|
|
1747
|
+
declare const makeFileVersion: (ctx: RakeDbCtx, config: Pick<RakeDbConfig, 'migrationId' | 'renameMigrations' | 'migrations' | 'basePath' | 'import' | 'migrationsPath'>) => Promise<string>;
|
|
1763
1748
|
|
|
1764
1749
|
declare class RakeDbError extends Error {
|
|
1765
1750
|
}
|
|
1766
1751
|
|
|
1767
|
-
|
|
1768
|
-
interface RakeDbCommand {
|
|
1769
|
-
run(adapters: AdapterBase[], config: AnyRakeDbConfig, args: string[]): MaybePromise<unknown>;
|
|
1770
|
-
help: string;
|
|
1771
|
-
helpArguments?: RecordString;
|
|
1772
|
-
helpAfter?: string;
|
|
1773
|
-
}
|
|
1774
|
-
interface RakeDbCommands {
|
|
1775
|
-
[K: string]: RakeDbCommand;
|
|
1776
|
-
}
|
|
1777
|
-
declare const rakeDbCommands: RakeDbCommands;
|
|
1778
|
-
|
|
1779
|
-
export { type AnyRakeDbConfig, type ChangeCallback, type DbMigration, DbStructure, type InputRakeDbConfig, type InputRakeDbConfigBase, type IntrospectedStructure, type MigrateFnConfig, RakeDbAst, type RakeDbChangeFn, type RakeDbChangeFnWithPromise, type RakeDbConfig, RakeDbError, type RakeDbFn, type SilentQueries, type StructureToAstCtx, type StructureToAstTableData, astToMigration, concatSchemaAndName, createMigrationInterface, dbColumnToAst, encodeColumnDefault, getConstraintName, getDbStructureTableData, getDbTableColumnsChecks, getExcludeName, getIndexName, getMigrationsSchemaAndTable, getSchemaAndTableFromName, instantiateDbColumn, introspectDbSchema, makeChange, makeDomainsMap, makeFileVersion, makeMigrateAdapter, makeStructureToAstCtx, migrate, migrateAndClose, migrateFiles, migrationConfigDefaults, processRakeDbConfig, promptSelect, rakeDbCommands, rakeDbWithAdapters, runCommand, saveMigratedVersion, structureToAst, tableToAst, writeMigrationFile };
|
|
1752
|
+
export { type ChangeCallback, type DbMigration, DbStructure, type IntrospectedStructure, RakeDbAst, type RakeDbChangeFn, type RakeDbCliConfigInput, type RakeDbConfig, RakeDbError, type RakeDbFn, type SilentQueries, type StructureToAstCtx, type StructureToAstTableData, astToMigration, concatSchemaAndName, createMigrationInterface, dbColumnToAst, encodeColumnDefault, getConstraintName, getDbStructureTableData, getDbTableColumnsChecks, getExcludeName, getIndexName, getMigrationsSchemaAndTable, getSchemaAndTableFromName, incrementIntermediateCaller, instantiateDbColumn, introspectDbSchema, makeDomainsMap, makeFileVersion, makeRakeDbConfig, makeStructureToAstCtx, migrate, migrateAndClose, migrationConfigDefaults, promptSelect, rakeDbCliWithAdapter, rakeDbCommands, redo, rollback, runMigration, saveMigratedVersion, setRakeDbCliRunFn, structureToAst, tableToAst, writeMigrationFile };
|