rake-db 2.26.0 → 2.27.3
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 +77 -40
- package/dist/index.js +289 -301
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +288 -301
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import * as pqb from 'pqb';
|
|
2
|
-
import { ColumnsShape, Db, TableData, NoPrimaryKeyOption, ColumnType, EnumColumn, DefaultColumnTypes, DefaultSchemaConfig, AdapterOptions, DbResult, Adapter, TransactionAdapter, TableDataFn, TableDataItem, DbDomainArg, raw, SearchWeight, ColumnsByType, DbStructureDomainsMap } from 'pqb';
|
|
3
1
|
import * as orchid_core from 'orchid-core';
|
|
4
|
-
import { MaybeArray, RawSQLBase, ColumnDataCheckBase, RecordString, ColumnTypeBase, EmptyObject, ColumnSchemaConfig, QueryLogOptions, MaybePromise, QueryLogObject, QueryBase } from 'orchid-core';
|
|
2
|
+
import { MaybeArray, RawSQLBase, ColumnDataCheckBase, RecordString, ColumnTypeBase, EmptyObject, ColumnSchemaConfig, QueryLogOptions, AdapterBase, MaybePromise, QueryLogObject, QueryBase } from 'orchid-core';
|
|
3
|
+
import * as pqb from 'pqb';
|
|
4
|
+
import { ColumnsShape, Db, TableData, NoPrimaryKeyOption, ColumnType, EnumColumn, DefaultColumnTypes, DefaultSchemaConfig, DbResult, TableDataFn, TableDataItem, DbDomainArg, raw, SearchWeight, ColumnsByType, DbStructureDomainsMap } from 'pqb';
|
|
5
5
|
|
|
6
6
|
interface CreateTableResult<Table extends string, Shape extends ColumnsShape> {
|
|
7
7
|
table: Db<Table, Shape>;
|
|
@@ -298,49 +298,71 @@ interface MigrationsSet {
|
|
|
298
298
|
}
|
|
299
299
|
|
|
300
300
|
interface CommandFn<SchemaConfig extends ColumnSchemaConfig, CT> {
|
|
301
|
-
(
|
|
301
|
+
(adapters: AdapterBase[], config: RakeDbConfig<SchemaConfig, CT>, args: string[]): void | Promise<void>;
|
|
302
302
|
}
|
|
303
|
-
interface
|
|
304
|
-
|
|
305
|
-
|
|
303
|
+
interface PickBasePath {
|
|
304
|
+
basePath: string;
|
|
305
|
+
}
|
|
306
|
+
interface PickImport {
|
|
307
|
+
import(path: string): Promise<unknown>;
|
|
308
|
+
}
|
|
309
|
+
interface PickMigrationId {
|
|
306
310
|
migrationId: RakeDbMigrationId;
|
|
311
|
+
}
|
|
312
|
+
interface PickMigrations {
|
|
307
313
|
migrations?: ModuleExportsRecord;
|
|
314
|
+
}
|
|
315
|
+
interface PickMigrationsPath {
|
|
316
|
+
migrationsPath: string;
|
|
317
|
+
}
|
|
318
|
+
interface PickOptionalMigrationsPath {
|
|
319
|
+
migrationsPath?: string;
|
|
320
|
+
}
|
|
321
|
+
interface PickRenameMigrations {
|
|
308
322
|
renameMigrations?: RakeDbRenameMigrationsInput;
|
|
323
|
+
}
|
|
324
|
+
interface PickMigrationsTable {
|
|
309
325
|
migrationsTable: string;
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
commands: Record<string, CommandFn<SchemaConfig, CT>>;
|
|
313
|
-
noPrimaryKey?: NoPrimaryKeyOption;
|
|
314
|
-
baseTable?: RakeDbBaseTable<CT>;
|
|
315
|
-
forceDefaultExports?: boolean;
|
|
316
|
-
import(path: string): Promise<unknown>;
|
|
326
|
+
}
|
|
327
|
+
interface PickMigrationCallbacks {
|
|
317
328
|
beforeChange?: ChangeCallback$1;
|
|
318
329
|
afterChange?: ChangeCallback$1;
|
|
319
|
-
afterChangeCommit?: ChangeCommitCallback;
|
|
320
330
|
beforeMigrate?: MigrationCallback;
|
|
321
331
|
afterMigrate?: MigrationCallback;
|
|
322
332
|
beforeRollback?: MigrationCallback;
|
|
323
333
|
afterRollback?: MigrationCallback;
|
|
324
334
|
}
|
|
325
|
-
interface
|
|
335
|
+
interface PickAfterChangeCommit {
|
|
336
|
+
afterChangeCommit?: ChangeCommitCallback;
|
|
337
|
+
}
|
|
338
|
+
interface PickForceDefaultExports {
|
|
339
|
+
forceDefaultExports?: boolean;
|
|
340
|
+
}
|
|
341
|
+
interface RakeDbBaseConfig<SchemaConfig extends ColumnSchemaConfig, CT = DefaultColumnTypes<DefaultSchemaConfig>> extends QueryLogOptions, PickImport, PickMigrationId, PickMigrationsPath, PickMigrations, PickRenameMigrations, PickMigrationsTable, PickMigrationCallbacks, PickForceDefaultExports, PickAfterChangeCommit {
|
|
342
|
+
schemaConfig: SchemaConfig;
|
|
343
|
+
snakeCase: boolean;
|
|
344
|
+
language?: string;
|
|
345
|
+
commands: Record<string, CommandFn<SchemaConfig, CT>>;
|
|
346
|
+
noPrimaryKey?: NoPrimaryKeyOption;
|
|
347
|
+
baseTable?: RakeDbBaseTable<CT>;
|
|
348
|
+
}
|
|
349
|
+
interface RakeDbConfig<SchemaConfig extends ColumnSchemaConfig, CT = DefaultColumnTypes<DefaultSchemaConfig>> extends RakeDbBaseConfig<SchemaConfig, CT>, PickBasePath {
|
|
326
350
|
columnTypes: CT;
|
|
327
|
-
basePath: string;
|
|
328
351
|
dbScript: string;
|
|
329
352
|
recurrentPath: string;
|
|
330
353
|
}
|
|
331
|
-
interface InputRakeDbConfigBase<SchemaConfig extends ColumnSchemaConfig, CT> extends QueryLogOptions {
|
|
354
|
+
interface InputRakeDbConfigBase<SchemaConfig extends ColumnSchemaConfig, CT> extends QueryLogOptions, PickOptionalMigrationsPath {
|
|
332
355
|
columnTypes?: CT | ((t: DefaultColumnTypes<DefaultSchemaConfig>) => CT);
|
|
333
356
|
baseTable?: RakeDbBaseTable<CT>;
|
|
334
357
|
schemaConfig?: SchemaConfig;
|
|
335
358
|
basePath?: string;
|
|
336
359
|
dbScript?: string;
|
|
337
|
-
migrationsPath?: string;
|
|
338
360
|
migrationId?: 'serial' | RakeDbMigrationId;
|
|
339
361
|
recurrentPath?: string;
|
|
340
362
|
migrationsTable?: string;
|
|
341
363
|
snakeCase?: boolean;
|
|
342
364
|
language?: string;
|
|
343
|
-
commands?: Record<string, (
|
|
365
|
+
commands?: Record<string, (adapter: AdapterBase[], config: RakeDbConfig<SchemaConfig, CT>, args: string[]) => void | Promise<void>>;
|
|
344
366
|
noPrimaryKey?: NoPrimaryKeyOption;
|
|
345
367
|
forceDefaultExports?: boolean;
|
|
346
368
|
/**
|
|
@@ -429,7 +451,7 @@ interface ChangeCallback$1 {
|
|
|
429
451
|
}
|
|
430
452
|
interface ChangeCommitCallback {
|
|
431
453
|
(arg: {
|
|
432
|
-
|
|
454
|
+
adapter: AdapterBase;
|
|
433
455
|
up: boolean;
|
|
434
456
|
migrations: MigrationItem[];
|
|
435
457
|
}): void | Promise<void>;
|
|
@@ -493,12 +515,15 @@ type ChangeTableOptions = {
|
|
|
493
515
|
};
|
|
494
516
|
type ChangeTableCallback<CT> = (t: TableChanger<CT>) => TableChangeData;
|
|
495
517
|
type SilentQueries = {
|
|
496
|
-
silentQuery:
|
|
497
|
-
silentArrays:
|
|
518
|
+
silentQuery: AdapterBase['query'];
|
|
519
|
+
silentArrays: AdapterBase['arrays'];
|
|
498
520
|
};
|
|
499
521
|
type DbMigration<CT> = DbResult<CT> & Migration<CT> & {
|
|
500
522
|
adapter: SilentQueries;
|
|
501
523
|
};
|
|
524
|
+
interface CreateMigrationInterfaceConfig<CT> extends QueryLogOptions {
|
|
525
|
+
columnTypes: CT;
|
|
526
|
+
}
|
|
502
527
|
/**
|
|
503
528
|
* Creates a new `db` instance that is an instance of `pqb` with mixed in migration methods from the `Migration` class.
|
|
504
529
|
* It overrides `query` and `array` db adapter methods to intercept SQL for the logging.
|
|
@@ -507,8 +532,8 @@ type DbMigration<CT> = DbResult<CT> & Migration<CT> & {
|
|
|
507
532
|
* @param up - migrate or rollback
|
|
508
533
|
* @param config - config of `rakeDb`
|
|
509
534
|
*/
|
|
510
|
-
declare const createMigrationInterface: <
|
|
511
|
-
interface MigrationAdapter extends
|
|
535
|
+
declare const createMigrationInterface: <CT>(tx: AdapterBase, up: boolean, config: CreateMigrationInterfaceConfig<CT>) => DbMigration<CT>;
|
|
536
|
+
interface MigrationAdapter extends AdapterBase {
|
|
512
537
|
schema: string;
|
|
513
538
|
}
|
|
514
539
|
declare class Migration<CT> {
|
|
@@ -1427,25 +1452,25 @@ interface MigrationChange {
|
|
|
1427
1452
|
type ChangeCallback<CT> = (db: DbMigration<CT>, up: boolean) => Promise<void>;
|
|
1428
1453
|
|
|
1429
1454
|
/**
|
|
1430
|
-
* Type of {@link
|
|
1455
|
+
* Type of {@link rakeDbWithAdapters} function
|
|
1431
1456
|
*/
|
|
1432
|
-
interface RakeDbFn {
|
|
1433
|
-
<SchemaConfig extends ColumnSchemaConfig, CT = DefaultColumnTypes<DefaultSchemaConfig>>(options:
|
|
1457
|
+
interface RakeDbFn<Options> {
|
|
1458
|
+
<SchemaConfig extends ColumnSchemaConfig, CT = DefaultColumnTypes<DefaultSchemaConfig>>(options: Options, partialConfig: InputRakeDbConfig<SchemaConfig, CT>, args?: string[]): RakeDbChangeFnWithPromise<CT>;
|
|
1434
1459
|
/**
|
|
1435
1460
|
* Unlike the original `rakeDb` that executes immediately,
|
|
1436
1461
|
* `rakeDb.lazy` returns the `run` function to be later called programmatically.
|
|
1437
1462
|
*
|
|
1438
|
-
* @param options -
|
|
1463
|
+
* @param options - array of connection adapters for migrating multiple dbs
|
|
1439
1464
|
* @param config - {@link RakeDbConfig}
|
|
1440
1465
|
* @returns `change` is to be used in migrations, `run` takes an array cli args to execute a command
|
|
1441
1466
|
*/
|
|
1442
|
-
lazy<SchemaConfig extends ColumnSchemaConfig, CT = DefaultColumnTypes<DefaultSchemaConfig>>(options:
|
|
1467
|
+
lazy<SchemaConfig extends ColumnSchemaConfig, CT = DefaultColumnTypes<DefaultSchemaConfig>>(options: Options, config: InputRakeDbConfig<SchemaConfig, CT>): {
|
|
1443
1468
|
change: RakeDbChangeFn<CT>;
|
|
1444
1469
|
run(args: string[], config?: Partial<RakeDbConfig<SchemaConfig, CT>>): Promise<RakeDbResult>;
|
|
1445
1470
|
};
|
|
1446
1471
|
}
|
|
1447
1472
|
interface RakeDbResult {
|
|
1448
|
-
|
|
1473
|
+
adapters: AdapterBase[];
|
|
1449
1474
|
config: AnyRakeDbConfig;
|
|
1450
1475
|
args: string[];
|
|
1451
1476
|
}
|
|
@@ -1463,13 +1488,13 @@ interface RakeDbChangeFnWithPromise<CT> extends RakeDbChangeFn<CT> {
|
|
|
1463
1488
|
/**
|
|
1464
1489
|
* Function to configure and run `rakeDb`.
|
|
1465
1490
|
*
|
|
1466
|
-
* @param options - {@link
|
|
1491
|
+
* @param options - {@link NodePostgresAdapterOptions} or an array of such options to migrate multiple dbs
|
|
1467
1492
|
* @param config - {@link RakeDbConfig}
|
|
1468
1493
|
* @param args - optionally provide an array of cli args. Default is `process.argv.slice(2)`.
|
|
1469
1494
|
*/
|
|
1470
|
-
declare const
|
|
1495
|
+
declare const rakeDbWithAdapters: RakeDbFn<AdapterBase[]>;
|
|
1471
1496
|
interface RakeDbCommand {
|
|
1472
|
-
run(
|
|
1497
|
+
run(adapters: AdapterBase[], config: AnyRakeDbConfig, args: string[]): MaybePromise<unknown>;
|
|
1473
1498
|
help: string;
|
|
1474
1499
|
helpArguments?: RecordString;
|
|
1475
1500
|
helpAfter?: string;
|
|
@@ -1504,9 +1529,17 @@ declare const promptSelect: ({ message, options, active, inactive, }: {
|
|
|
1504
1529
|
inactive?: (s: string) => string;
|
|
1505
1530
|
}) => Promise<number>;
|
|
1506
1531
|
|
|
1507
|
-
declare const saveMigratedVersion:
|
|
1532
|
+
declare const saveMigratedVersion: (db: SilentQueries, version: string, name: string, config: PickMigrationsTable) => Promise<void>;
|
|
1508
1533
|
|
|
1509
|
-
|
|
1534
|
+
interface MigrateFnConfig extends MigrateOrRollbackConfig, PickAfterChangeCommit, PickBasePath, PickImport, PickMigrationsPath {
|
|
1535
|
+
}
|
|
1536
|
+
type MigrateFn = (params: {
|
|
1537
|
+
ctx?: RakeDbCtx;
|
|
1538
|
+
adapter: AdapterBase;
|
|
1539
|
+
config: MigrateFnConfig;
|
|
1540
|
+
count?: number;
|
|
1541
|
+
force?: boolean;
|
|
1542
|
+
}) => Promise<void>;
|
|
1510
1543
|
/**
|
|
1511
1544
|
* Will run all pending yet migrations, sequentially in order,
|
|
1512
1545
|
* will apply `change` functions top-to-bottom.
|
|
@@ -1515,7 +1548,11 @@ type MigrateFn = <SchemaConfig extends ColumnSchemaConfig, CT>(ctx: RakeDbCtx, o
|
|
|
1515
1548
|
* @param config - specifies how to load migrations, callbacks, and logger
|
|
1516
1549
|
* @param args - pass none or `all` to run all migrations, pass int for how many to migrate
|
|
1517
1550
|
*/
|
|
1518
|
-
declare const
|
|
1551
|
+
declare const migrate: MigrateFn;
|
|
1552
|
+
declare const migrateAndClose: MigrateFn;
|
|
1553
|
+
interface MigrateOrRollbackConfig extends PickMigrationCallbacks, PickMigrationId, QueryLogOptions, PickForceDefaultExports, PickMigrationsTable {
|
|
1554
|
+
columnTypes: unknown;
|
|
1555
|
+
}
|
|
1519
1556
|
|
|
1520
1557
|
declare namespace DbStructure {
|
|
1521
1558
|
interface TableNameAndSchemaName {
|
|
@@ -1679,7 +1716,7 @@ interface IntrospectedStructure {
|
|
|
1679
1716
|
domains: DbStructure.Domain[];
|
|
1680
1717
|
collations: DbStructure.Collation[];
|
|
1681
1718
|
}
|
|
1682
|
-
declare function introspectDbSchema(db:
|
|
1719
|
+
declare function introspectDbSchema(db: AdapterBase): Promise<IntrospectedStructure>;
|
|
1683
1720
|
|
|
1684
1721
|
declare const astToMigration: (currentSchema: string, config: AnyRakeDbConfig, asts: RakeDbAst[]) => string | undefined;
|
|
1685
1722
|
|
|
@@ -1697,7 +1734,7 @@ interface StructureToAstTableData {
|
|
|
1697
1734
|
constraints: DbStructure.Constraint[];
|
|
1698
1735
|
}
|
|
1699
1736
|
declare const makeStructureToAstCtx: (config: AnyRakeDbConfig, currentSchema: string) => StructureToAstCtx;
|
|
1700
|
-
declare const structureToAst: (ctx: StructureToAstCtx, adapter:
|
|
1737
|
+
declare const structureToAst: (ctx: StructureToAstCtx, adapter: AdapterBase, config: AnyRakeDbConfig) => Promise<RakeDbAst[]>;
|
|
1701
1738
|
declare const makeDomainsMap: (ctx: StructureToAstCtx, data: IntrospectedStructure) => DbStructureDomainsMap;
|
|
1702
1739
|
declare const instantiateDbColumn: (ctx: StructureToAstCtx, data: IntrospectedStructure, domains: DbStructureDomainsMap, dbColumn: DbStructure.Column) => ColumnType<orchid_core.ColumnTypeSchemaArg, unknown, any, any, unknown, unknown, any, unknown, any>;
|
|
1703
1740
|
declare const tableToAst: (ctx: StructureToAstCtx, data: IntrospectedStructure, table: DbStructure.Table, action: 'create' | 'drop', domains: DbStructureDomainsMap) => RakeDbAst.Table;
|
|
@@ -1717,4 +1754,4 @@ interface OrmParam {
|
|
|
1717
1754
|
type UnknownPromiseFns = (() => Promise<unknown>)[];
|
|
1718
1755
|
declare const migrateFiles: (db: OrmParam, files: UnknownPromiseFns) => Promise<void>;
|
|
1719
1756
|
|
|
1720
|
-
export { type AnyRakeDbConfig, type ChangeCallback, type DbMigration, DbStructure, type InputRakeDbConfigBase, type IntrospectedStructure, RakeDbAst, type RakeDbChangeFn, type RakeDbChangeFnWithPromise, type RakeDbConfig, type SilentQueries, type StructureToAstCtx, type StructureToAstTableData, astToMigration, concatSchemaAndName, createMigrationInterface, dbColumnToAst, encodeColumnDefault,
|
|
1757
|
+
export { type AnyRakeDbConfig, type ChangeCallback, type DbMigration, DbStructure, type InputRakeDbConfigBase, type IntrospectedStructure, RakeDbAst, type RakeDbChangeFn, type RakeDbChangeFnWithPromise, type RakeDbConfig, type SilentQueries, type StructureToAstCtx, type StructureToAstTableData, astToMigration, concatSchemaAndName, createMigrationInterface, dbColumnToAst, encodeColumnDefault, getConstraintName, getDbStructureTableData, getDbTableColumnsChecks, getExcludeName, getIndexName, getSchemaAndTableFromName, instantiateDbColumn, introspectDbSchema, makeDomainsMap, makeFileVersion, makeStructureToAstCtx, migrate, migrateAndClose, migrateFiles, migrationConfigDefaults, promptSelect, rakeDbCommands, rakeDbWithAdapters, saveMigratedVersion, structureToAst, tableToAst, writeMigrationFile };
|