rake-db 2.27.6 → 2.27.8
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 +19 -9
- package/dist/index.js +35 -17
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +31 -18
- package/dist/index.mjs.map +1 -1
- package/dist/node-postgres.d.ts +2 -1463
- package/dist/node-postgres.js +9 -5848
- package/dist/node-postgres.js.map +1 -1
- package/dist/node-postgres.mjs +2 -5841
- package/dist/node-postgres.mjs.map +1 -1
- package/dist/postgres-js.d.ts +2 -1463
- package/dist/postgres-js.js +9 -5848
- package/dist/postgres-js.js.map +1 -1
- package/dist/postgres-js.mjs +2 -5841
- package/dist/postgres-js.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -254,14 +254,14 @@ declare const tableChangeMethods: {
|
|
|
254
254
|
columns: Columns;
|
|
255
255
|
name: string extends Name ? never : Name;
|
|
256
256
|
};
|
|
257
|
-
unique<Columns_1 extends [string | TableData.Index.ColumnOrExpressionOptions<string>, ...(string | TableData.Index.ColumnOrExpressionOptions<string>)[]], Name_1 extends string>(columns: Columns_1,
|
|
257
|
+
unique<Columns_1 extends [string | TableData.Index.ColumnOrExpressionOptions<string>, ...(string | TableData.Index.ColumnOrExpressionOptions<string>)[]], Name_1 extends string>(columns: Columns_1, options?: TableData.Index.UniqueOptionsArg<Name_1> | undefined): {
|
|
258
258
|
tableDataItem: true;
|
|
259
259
|
columns: Columns_1 extends (string | TableData.Index.ColumnOptionsForColumn<string>)[] ? { [I in keyof Columns_1]: "column" extends keyof Columns_1[I] ? Columns_1[I][keyof Columns_1[I] & "column"] : Columns_1[I]; } : never;
|
|
260
260
|
name: string extends Name_1 ? never : Name_1;
|
|
261
261
|
};
|
|
262
|
-
index(columns: (string | TableData.Index.ColumnOrExpressionOptions<string>)[],
|
|
263
|
-
searchIndex(columns: (string | TableData.Index.ColumnOrExpressionOptions<string>)[],
|
|
264
|
-
exclude(columns: TableData.Exclude.ColumnOrExpressionOptions<string>[],
|
|
262
|
+
index(columns: (string | TableData.Index.ColumnOrExpressionOptions<string>)[], options?: TableData.Index.OptionsArg | undefined): pqb.NonUniqDataItem;
|
|
263
|
+
searchIndex(columns: (string | TableData.Index.ColumnOrExpressionOptions<string>)[], options?: TableData.Index.TsVectorArg | undefined): pqb.NonUniqDataItem;
|
|
264
|
+
exclude(columns: TableData.Exclude.ColumnOrExpressionOptions<string>[], options?: TableData.Exclude.Options | undefined): pqb.NonUniqDataItem;
|
|
265
265
|
foreignKey<ForeignTable extends string | (() => orchid_core.ForeignKeyTable), ForeignColumns extends ForeignTable extends () => orchid_core.ForeignKeyTable ? [orchid_core.ColumnNameOfTable<ReturnType<ForeignTable>>, ...orchid_core.ColumnNameOfTable<ReturnType<ForeignTable>>[]] : [string, ...string[]]>(columns: [string, ...string[]], fnOrTable: ForeignTable, foreignColumns: ForeignColumns, options?: TableData.References.Options | undefined): pqb.NonUniqDataItem;
|
|
266
266
|
check(check: RawSQLBase<orchid_core.QueryColumn<unknown, any>, unknown>, name?: string | undefined): pqb.NonUniqDataItem;
|
|
267
267
|
sql: pqb.SqlFn;
|
|
@@ -491,6 +491,7 @@ interface RakeDbRenameMigrationsInput {
|
|
|
491
491
|
map: RakeDbRenameMigrationsMap;
|
|
492
492
|
}
|
|
493
493
|
declare const migrationConfigDefaults: RakeDbBaseConfig<ColumnSchemaConfig>;
|
|
494
|
+
declare const processRakeDbConfig: <SchemaConfig extends ColumnSchemaConfig<orchid_core.ColumnTypeBase<orchid_core.ColumnTypeSchemaArg, unknown, any, any, unknown, unknown, any, unknown, any, orchid_core.ColumnDataBase>>, CT>(config: InputRakeDbConfig<SchemaConfig, CT>) => RakeDbConfig<SchemaConfig, CT>;
|
|
494
495
|
|
|
495
496
|
type DropMode = 'CASCADE' | 'RESTRICT';
|
|
496
497
|
type TableOptions = {
|
|
@@ -771,17 +772,17 @@ declare class Migration<CT> {
|
|
|
771
772
|
*
|
|
772
773
|
* @param tableName - name of the table to add the index for
|
|
773
774
|
* @param columns - indexed columns
|
|
774
|
-
* @param args - index options
|
|
775
|
+
* @param args - index options
|
|
775
776
|
*/
|
|
776
|
-
addIndex(tableName: string, columns: (string | TableData.Index.ColumnOrExpressionOptions
|
|
777
|
+
addIndex(tableName: string, columns: (string | TableData.Index.ColumnOrExpressionOptions)[], ...args: [options?: TableData.Index.OptionsArg]): Promise<void>;
|
|
777
778
|
/**
|
|
778
779
|
* Drop the schema, create it on rollback. See {@link addIndex}.
|
|
779
780
|
*
|
|
780
781
|
* @param tableName - name of the table to add the index for
|
|
781
782
|
* @param columns - indexed columns
|
|
782
|
-
* @param args - index options
|
|
783
|
+
* @param args - index options
|
|
783
784
|
*/
|
|
784
|
-
dropIndex(tableName: string, columns: (string | TableData.Index.ColumnOrExpressionOptions
|
|
785
|
+
dropIndex(tableName: string, columns: (string | TableData.Index.ColumnOrExpressionOptions)[], ...args: [options?: TableData.Index.OptionsArg]): Promise<void>;
|
|
785
786
|
/**
|
|
786
787
|
* Rename index:
|
|
787
788
|
*
|
|
@@ -1493,6 +1494,8 @@ interface RakeDbChangeFnWithPromise<CT> extends RakeDbChangeFn<CT> {
|
|
|
1493
1494
|
* @param args - optionally provide an array of cli args. Default is `process.argv.slice(2)`.
|
|
1494
1495
|
*/
|
|
1495
1496
|
declare const rakeDbWithAdapters: RakeDbFn<AdapterBase[]>;
|
|
1497
|
+
declare const makeChange: (config: RakeDbConfig<ColumnSchemaConfig, unknown>) => (fn: ChangeCallback<unknown>) => MigrationChange;
|
|
1498
|
+
declare const runCommand: <SchemaConfig extends ColumnSchemaConfig<orchid_core.ColumnTypeBase<orchid_core.ColumnTypeSchemaArg, unknown, any, any, unknown, unknown, any, unknown, any, orchid_core.ColumnDataBase>>, CT>(adapters: AdapterBase[], config: RakeDbConfig<SchemaConfig, CT>, args?: string[]) => Promise<RakeDbResult>;
|
|
1496
1499
|
interface RakeDbCommand {
|
|
1497
1500
|
run(adapters: AdapterBase[], config: AnyRakeDbConfig, args: string[]): MaybePromise<unknown>;
|
|
1498
1501
|
help: string;
|
|
@@ -1753,5 +1756,12 @@ interface OrmParam {
|
|
|
1753
1756
|
}
|
|
1754
1757
|
type UnknownPromiseFns = (() => Promise<unknown>)[];
|
|
1755
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>);
|
|
1763
|
+
|
|
1764
|
+
declare class RakeDbError extends Error {
|
|
1765
|
+
}
|
|
1756
1766
|
|
|
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 };
|
|
1767
|
+
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, getSchemaAndTableFromName, instantiateDbColumn, introspectDbSchema, makeChange, makeDomainsMap, makeFileVersion, makeMigrateAdapter, makeStructureToAstCtx, migrate, migrateAndClose, migrateFiles, migrationConfigDefaults, processRakeDbConfig, promptSelect, rakeDbCommands, rakeDbWithAdapters, runCommand, saveMigratedVersion, structureToAst, tableToAst, writeMigrationFile };
|
package/dist/index.js
CHANGED
|
@@ -420,7 +420,7 @@ const getIndexOrExcludeMainOptions = (tableName, item, getName, snakeCase) => {
|
|
|
420
420
|
return {
|
|
421
421
|
columns,
|
|
422
422
|
include,
|
|
423
|
-
name: item.name || getName(tableName, columns)
|
|
423
|
+
name: item.options?.name || getName(tableName, columns)
|
|
424
424
|
};
|
|
425
425
|
};
|
|
426
426
|
const commentsToQuery = (schemaTable, comments) => {
|
|
@@ -1512,20 +1512,20 @@ class Migration {
|
|
|
1512
1512
|
*
|
|
1513
1513
|
* @param tableName - name of the table to add the index for
|
|
1514
1514
|
* @param columns - indexed columns
|
|
1515
|
-
* @param args - index options
|
|
1515
|
+
* @param args - index options
|
|
1516
1516
|
*/
|
|
1517
1517
|
addIndex(tableName, columns, ...args) {
|
|
1518
|
-
return addIndex(this, this.up, tableName, columns, args);
|
|
1518
|
+
return addIndex(this, this.up, tableName, columns, ...args);
|
|
1519
1519
|
}
|
|
1520
1520
|
/**
|
|
1521
1521
|
* Drop the schema, create it on rollback. See {@link addIndex}.
|
|
1522
1522
|
*
|
|
1523
1523
|
* @param tableName - name of the table to add the index for
|
|
1524
1524
|
* @param columns - indexed columns
|
|
1525
|
-
* @param args - index options
|
|
1525
|
+
* @param args - index options
|
|
1526
1526
|
*/
|
|
1527
1527
|
dropIndex(tableName, columns, ...args) {
|
|
1528
|
-
return addIndex(this, !this.up, tableName, columns, args);
|
|
1528
|
+
return addIndex(this, !this.up, tableName, columns, ...args);
|
|
1529
1529
|
}
|
|
1530
1530
|
/**
|
|
1531
1531
|
* Rename index:
|
|
@@ -2250,7 +2250,7 @@ const addColumn = (migration, up, tableName, columnName, fn) => {
|
|
|
2250
2250
|
[columnName]: t.add(fn(t))
|
|
2251
2251
|
}));
|
|
2252
2252
|
};
|
|
2253
|
-
const addIndex = (migration, up, tableName, columns, args) => {
|
|
2253
|
+
const addIndex = (migration, up, tableName, columns, ...args) => {
|
|
2254
2254
|
return changeTable(migration, up, tableName, {}, (t) => ({
|
|
2255
2255
|
...t.add(t.index(columns, ...args))
|
|
2256
2256
|
}));
|
|
@@ -4260,11 +4260,7 @@ const tableToAst = (ctx, data, table, action, domains) => {
|
|
|
4260
4260
|
const indexesOrExcludesToAst = (tableName, tableData, key) => {
|
|
4261
4261
|
return tableData[key].reduce((acc, item) => {
|
|
4262
4262
|
if (item.columns.length > 1 || item.columns.some((it) => "expression" in it)) {
|
|
4263
|
-
const
|
|
4264
|
-
tableName,
|
|
4265
|
-
item,
|
|
4266
|
-
key
|
|
4267
|
-
);
|
|
4263
|
+
const options = makeIndexOrExcludeOptions(tableName, item, key);
|
|
4268
4264
|
acc.push({
|
|
4269
4265
|
columns: item.columns.map((it, i) => ({
|
|
4270
4266
|
with: "exclude" in item && item.exclude ? item.exclude[i] : void 0,
|
|
@@ -4276,8 +4272,7 @@ const indexesOrExcludesToAst = (tableName, tableData, key) => {
|
|
|
4276
4272
|
options: {
|
|
4277
4273
|
...options,
|
|
4278
4274
|
include: item.include?.map(orchidCore.toCamelCase)
|
|
4279
|
-
}
|
|
4280
|
-
name
|
|
4275
|
+
}
|
|
4281
4276
|
});
|
|
4282
4277
|
}
|
|
4283
4278
|
return acc;
|
|
@@ -4444,12 +4439,12 @@ const collectColumnIndexesOrExcludes = (dbColumn, column, tableName, tableData,
|
|
|
4444
4439
|
((_a = column.data)[key] ?? (_a[key] = [])).push({
|
|
4445
4440
|
with: "exclude" in item && item.exclude ? item.exclude[0] : void 0,
|
|
4446
4441
|
options: {
|
|
4442
|
+
name,
|
|
4447
4443
|
collate: columnOptions.collate,
|
|
4448
4444
|
opclass: columnOptions.opclass,
|
|
4449
4445
|
order: columnOptions.order,
|
|
4450
4446
|
...itemOptions
|
|
4451
|
-
}
|
|
4452
|
-
name
|
|
4447
|
+
}
|
|
4453
4448
|
});
|
|
4454
4449
|
}
|
|
4455
4450
|
};
|
|
@@ -4729,7 +4724,7 @@ const pushIndexOrExcludeKeys = (change, keys, schema, table, name, key) => {
|
|
|
4729
4724
|
const getName = key === "indexes" ? getIndexName : getExcludeName;
|
|
4730
4725
|
for (const x of items) {
|
|
4731
4726
|
keys.push(
|
|
4732
|
-
x.name ? `${schema}.${x.name}` : getName(table, [{ column: change.column?.data.name ?? name }])
|
|
4727
|
+
x.options.name ? `${schema}.${x.options.name}` : getName(table, [{ column: change.column?.data.name ?? name }])
|
|
4733
4728
|
);
|
|
4734
4729
|
}
|
|
4735
4730
|
}
|
|
@@ -4739,7 +4734,9 @@ const pushIndexesOrExcludesKeys = (keys, schema, table, data, key) => {
|
|
|
4739
4734
|
if (arr) {
|
|
4740
4735
|
const getName = key === "indexes" ? getIndexName : getExcludeName;
|
|
4741
4736
|
for (const x of arr) {
|
|
4742
|
-
keys.push(
|
|
4737
|
+
keys.push(
|
|
4738
|
+
x.options.name ? `${schema}.${x.options.name}` : getName(table, x.columns)
|
|
4739
|
+
);
|
|
4743
4740
|
}
|
|
4744
4741
|
}
|
|
4745
4742
|
};
|
|
@@ -5863,7 +5860,24 @@ const migrateFiles = async (db, files) => {
|
|
|
5863
5860
|
}
|
|
5864
5861
|
});
|
|
5865
5862
|
};
|
|
5863
|
+
const makeMigrateAdapter = (config) => {
|
|
5864
|
+
const conf = ensureMigrationsPath(ensureBasePathAndDbScript(config || {}));
|
|
5865
|
+
return async (adapter, params) => {
|
|
5866
|
+
await migrateAndClose({
|
|
5867
|
+
adapter,
|
|
5868
|
+
...params,
|
|
5869
|
+
config: {
|
|
5870
|
+
...conf,
|
|
5871
|
+
columnTypes: conf.columnTypes || pqb.makeColumnTypes(pqb.defaultSchemaConfig),
|
|
5872
|
+
migrationId: conf.migrationId || migrationConfigDefaults.migrationId,
|
|
5873
|
+
migrationsTable: conf.migrationsTable || migrationConfigDefaults.migrationsTable,
|
|
5874
|
+
import: conf.import || migrationConfigDefaults.import
|
|
5875
|
+
}
|
|
5876
|
+
});
|
|
5877
|
+
};
|
|
5878
|
+
};
|
|
5866
5879
|
|
|
5880
|
+
exports.RakeDbError = RakeDbError;
|
|
5867
5881
|
exports.astToMigration = astToMigration;
|
|
5868
5882
|
exports.concatSchemaAndName = concatSchemaAndName;
|
|
5869
5883
|
exports.createMigrationInterface = createMigrationInterface;
|
|
@@ -5877,16 +5891,20 @@ exports.getIndexName = getIndexName;
|
|
|
5877
5891
|
exports.getSchemaAndTableFromName = getSchemaAndTableFromName;
|
|
5878
5892
|
exports.instantiateDbColumn = instantiateDbColumn;
|
|
5879
5893
|
exports.introspectDbSchema = introspectDbSchema;
|
|
5894
|
+
exports.makeChange = makeChange;
|
|
5880
5895
|
exports.makeDomainsMap = makeDomainsMap;
|
|
5881
5896
|
exports.makeFileVersion = makeFileVersion;
|
|
5897
|
+
exports.makeMigrateAdapter = makeMigrateAdapter;
|
|
5882
5898
|
exports.makeStructureToAstCtx = makeStructureToAstCtx;
|
|
5883
5899
|
exports.migrate = migrate;
|
|
5884
5900
|
exports.migrateAndClose = migrateAndClose;
|
|
5885
5901
|
exports.migrateFiles = migrateFiles;
|
|
5886
5902
|
exports.migrationConfigDefaults = migrationConfigDefaults;
|
|
5903
|
+
exports.processRakeDbConfig = processRakeDbConfig;
|
|
5887
5904
|
exports.promptSelect = promptSelect;
|
|
5888
5905
|
exports.rakeDbCommands = rakeDbCommands;
|
|
5889
5906
|
exports.rakeDbWithAdapters = rakeDbWithAdapters;
|
|
5907
|
+
exports.runCommand = runCommand;
|
|
5890
5908
|
exports.saveMigratedVersion = saveMigratedVersion;
|
|
5891
5909
|
exports.structureToAst = structureToAst;
|
|
5892
5910
|
exports.tableToAst = tableToAst;
|