rake-db 2.19.0 → 2.20.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 CHANGED
@@ -1293,7 +1293,10 @@ interface InputRakeDbConfig<SchemaConfig extends ColumnSchemaConfig, CT> extends
1293
1293
  commands?: Record<string, (options: AdapterOptions[], config: RakeDbConfig<SchemaConfig, CT extends undefined ? DefaultColumnTypes<DefaultSchemaConfig> : CT>, args: string[]) => void | Promise<void>>;
1294
1294
  noPrimaryKey?: NoPrimaryKeyOption;
1295
1295
  forceDefaultExports?: boolean;
1296
- import?(path: string): Promise<unknown>;
1296
+ /**
1297
+ * It may look odd, but it's required for `tsx` and other bundlers to have such `import` config specified explicitly.
1298
+ */
1299
+ import(path: string): Promise<unknown>;
1297
1300
  /**
1298
1301
  * Is called once per db before migrating or rolling back a set of migrations.
1299
1302
  *
@@ -1390,7 +1393,6 @@ declare const migrationConfigDefaults: {
1390
1393
  migrationsTable: string;
1391
1394
  snakeCase: false;
1392
1395
  commands: {};
1393
- import: (path: string) => Promise<any>;
1394
1396
  log: true;
1395
1397
  logger: Console;
1396
1398
  };
@@ -1629,7 +1631,7 @@ interface StructureToAstTableData {
1629
1631
  constraints: DbStructure.Constraint[];
1630
1632
  }
1631
1633
  declare const makeStructureToAstCtx: (config: AnyRakeDbConfig, currentSchema: string) => StructureToAstCtx;
1632
- declare const structureToAst: (ctx: StructureToAstCtx, adapter: Adapter) => Promise<RakeDbAst[]>;
1634
+ declare const structureToAst: (ctx: StructureToAstCtx, adapter: Adapter, config: AnyRakeDbConfig) => Promise<RakeDbAst[]>;
1633
1635
  declare const makeDomainsMap: (ctx: StructureToAstCtx, data: IntrospectedStructure) => DbStructureDomainsMap;
1634
1636
  declare const instantiateDbColumn: (ctx: StructureToAstCtx, data: IntrospectedStructure, domains: DbStructureDomainsMap, dbColumn: DbStructure.Column) => ColumnType<orchid_core.ColumnTypeSchemaArg, unknown, any, pqb.BaseOperators, unknown, unknown, any, unknown, any> | ArrayColumn<ColumnSchemaConfig<orchid_core.ColumnTypeBase<orchid_core.ColumnTypeSchemaArg, unknown, any, orchid_core.CoreBaseOperators, unknown, unknown, any, unknown, any, orchid_core.ColumnDataBase>>, ColumnType<orchid_core.ColumnTypeSchemaArg, unknown, any, pqb.BaseOperators, unknown, unknown, any, unknown, any>, unknown, unknown, unknown>;
1635
1637
  declare const tableToAst: (ctx: StructureToAstCtx, data: IntrospectedStructure, table: DbStructure.Table, action: 'create' | 'drop', domains: DbStructureDomainsMap) => RakeDbAst.Table;
@@ -1683,7 +1685,7 @@ declare const primaryKeyToSql: (primaryKey: Exclude<TableData['primaryKey'], und
1683
1685
  /**
1684
1686
  * Type of {@link rakeDb} function
1685
1687
  */
1686
- type RakeDbFn = (<SchemaConfig extends ColumnSchemaConfig, CT>(options: MaybeArray<AdapterOptions>, partialConfig?: InputRakeDbConfig<SchemaConfig, CT>, args?: string[]) => RakeDbFnReturns<CT>) & {
1688
+ type RakeDbFn = (<SchemaConfig extends ColumnSchemaConfig, CT>(options: MaybeArray<AdapterOptions>, partialConfig: InputRakeDbConfig<SchemaConfig, CT>, args?: string[]) => RakeDbFnReturns<CT>) & {
1687
1689
  /**
1688
1690
  * Unlike the original `rakeDb` that executes immediately,
1689
1691
  * `rakeDb.lazy` returns the `run` function to be later called programmatically.
@@ -1705,7 +1707,7 @@ interface RakeDbResult {
1705
1707
  /**
1706
1708
  * Type of {@link rakeDb.lazy} function
1707
1709
  */
1708
- type RakeDbLazyFn = <SchemaConfig extends ColumnSchemaConfig, CT>(options: MaybeArray<AdapterOptions>, partialConfig?: InputRakeDbConfig<SchemaConfig, CT>) => {
1710
+ type RakeDbLazyFn = <SchemaConfig extends ColumnSchemaConfig, CT>(options: MaybeArray<AdapterOptions>, partialConfig: InputRakeDbConfig<SchemaConfig, CT>) => {
1709
1711
  change: RakeDbChangeFn<CT>;
1710
1712
  run(args: string[], config?: Partial<RakeDbConfig<SchemaConfig, CT>>): Promise<RakeDbResult>;
1711
1713
  };
package/dist/index.js CHANGED
@@ -3089,15 +3089,6 @@ const migrationConfigDefaults = {
3089
3089
  migrationsTable: "schemaMigrations",
3090
3090
  snakeCase: false,
3091
3091
  commands: {},
3092
- import: (path2) => {
3093
- return import(path2).catch((err) => {
3094
- if (err.code === "ERR_UNKNOWN_FILE_EXTENSION") {
3095
- require(path2);
3096
- } else {
3097
- throw err;
3098
- }
3099
- });
3100
- },
3101
3092
  log: true,
3102
3093
  logger: console
3103
3094
  };
@@ -4041,7 +4032,7 @@ const makeStructureToAstCtx = (config, currentSchema) => ({
4041
4032
  columnSchemaConfig: config.schemaConfig,
4042
4033
  columnsByType: pqb.makeColumnsByType(config.schemaConfig)
4043
4034
  });
4044
- const structureToAst = async (ctx, adapter) => {
4035
+ const structureToAst = async (ctx, adapter, config) => {
4045
4036
  const ast = [];
4046
4037
  const data = await introspectDbSchema(adapter);
4047
4038
  for (const name of data.schemas) {
@@ -4063,7 +4054,7 @@ const structureToAst = async (ctx, adapter) => {
4063
4054
  }
4064
4055
  const domains = makeDomainsMap(ctx, data);
4065
4056
  for (const table of data.tables) {
4066
- if (table.name === "schemaMigrations")
4057
+ if (table.name === config.migrationsTable)
4067
4058
  continue;
4068
4059
  ast.push(tableToAst(ctx, data, table, "create", domains));
4069
4060
  }
@@ -5162,7 +5153,7 @@ const pullDbStructure = async (options, config) => {
5162
5153
  const adapter = new pqb.Adapter(options);
5163
5154
  const currentSchema = adapter.schema || "public";
5164
5155
  const ctx = makeStructureToAstCtx(config, currentSchema);
5165
- const ast = await structureToAst(ctx, adapter);
5156
+ const ast = await structureToAst(ctx, adapter, config);
5166
5157
  await adapter.close();
5167
5158
  const result = astToMigration(currentSchema, config, ast);
5168
5159
  if (!result)
@@ -5525,7 +5516,7 @@ var __spreadValues = (a, b) => {
5525
5516
  }
5526
5517
  return a;
5527
5518
  };
5528
- const rakeDb = (options, partialConfig = {}, args = process.argv.slice(2)) => {
5519
+ const rakeDb = (options, partialConfig, args = process.argv.slice(2)) => {
5529
5520
  const config = processRakeDbConfig(partialConfig);
5530
5521
  const promise = runCommand(
5531
5522
  options,
@@ -5543,7 +5534,7 @@ const rakeDb = (options, partialConfig = {}, args = process.argv.slice(2)) => {
5543
5534
  promise
5544
5535
  });
5545
5536
  };
5546
- rakeDb.lazy = (options, partialConfig = {}) => {
5537
+ rakeDb.lazy = (options, partialConfig) => {
5547
5538
  const config = processRakeDbConfig(partialConfig);
5548
5539
  return {
5549
5540
  change,