rake-db 2.29.0 → 2.29.2

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
@@ -1476,7 +1476,7 @@ interface RakeDbFn<Options> {
1476
1476
  run<SchemaConfig extends ColumnSchemaConfig, ColumnTypes = DefaultColumnTypes<DefaultSchemaConfig>>(options: Options, config: RakeDbCliConfigInput<SchemaConfig, ColumnTypes> | RakeDbConfig<ColumnTypes>, args?: string[]): RakeDbChangeFn<ColumnTypes>;
1477
1477
  }
1478
1478
  declare const rakeDbCliWithAdapter: RakeDbFn<MaybeArray<AdapterBase>>;
1479
- declare const setRakeDbCliRunFn: <T>(rakeDbCli: RakeDbFn<T>, mapper: (options: T) => unknown) => void;
1479
+ declare const setRakeDbCliRunFn: <T>(rakeDbCli: RakeDbFn<T>) => void;
1480
1480
  declare const rakeDbCommands: RakeDbCommands;
1481
1481
 
1482
1482
  declare const encodeColumnDefault: (def: unknown, values: unknown[], column?: Column.Pick.Data) => string | null;
@@ -1743,8 +1743,8 @@ interface ColumnChecks {
1743
1743
  declare const getDbTableColumnsChecks: (tableData: StructureToAstTableData) => ColumnChecks;
1744
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];
1745
1745
 
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>;
1746
+ declare const writeMigrationFile: (config: RakeDbConfig, version: string, name: string, migrationCode: string) => Promise<void>;
1747
+ declare const makeFileVersion: (ctx: RakeDbCtx, config: RakeDbConfig) => Promise<string>;
1748
1748
 
1749
1749
  declare class RakeDbError extends Error {
1750
1750
  }
package/dist/index.js CHANGED
@@ -3110,8 +3110,20 @@ const sortMigrationsAsc = (a, b) => +a.version - +b.version;
3110
3110
  async function getMigrationsFromFiles(config, allowDuplicates, getVersion = getMigrationVersionOrThrow) {
3111
3111
  const { migrationsPath, import: imp } = config;
3112
3112
  const entries = await fs.readdir(migrationsPath, { withFileTypes: true }).catch(
3113
- () => []
3113
+ (err) => ({ err })
3114
3114
  );
3115
+ if ("err" in entries) {
3116
+ if (entries.err.code === "ENOENT") {
3117
+ config.logger?.log(`Directory ${migrationsPath} does not exist`);
3118
+ return { migrations: [] };
3119
+ } else {
3120
+ throw entries.err;
3121
+ }
3122
+ } else if (!entries) {
3123
+ config.logger?.log(
3124
+ `Could not find any migration files in ${migrationsPath}`
3125
+ );
3126
+ }
3115
3127
  const versions = {};
3116
3128
  const result = entries.reduce(
3117
3129
  (data, file) => {
@@ -3661,8 +3673,8 @@ const createOrDropDatabase = async (action, adapters, config, dontClose) => {
3661
3673
  }
3662
3674
  };
3663
3675
  const resetDatabaseCommand = async (adapters, config) => {
3664
- await createOrDropDatabase("create", adapters, config);
3665
- await createOrDropDatabase("drop", adapters, config, true);
3676
+ await createOrDropDatabase("drop", adapters, config);
3677
+ await createOrDropDatabase("create", adapters, config, true);
3666
3678
  for (const adapter of adapters) {
3667
3679
  await migrate(adapter, config);
3668
3680
  }
@@ -5878,14 +5890,17 @@ const rakeDbCliWithAdapter = (inputConfig, args = process.argv.slice(2)) => {
5878
5890
  }
5879
5891
  };
5880
5892
  };
5881
- const setRakeDbCliRunFn = (rakeDbCli, mapper) => {
5882
- rakeDbCli.run = (adapter, inputConfig, args) => {
5893
+ const setRakeDbCliRunFn = (rakeDbCli) => {
5894
+ rakeDbCli.run = (options, inputConfig, args) => {
5895
+ if (!("__rakeDbConfig" in inputConfig)) {
5896
+ incrementIntermediateCaller();
5897
+ }
5883
5898
  const { change, run } = rakeDbCli(inputConfig, args);
5884
- run(mapper(adapter));
5899
+ run(options);
5885
5900
  return change;
5886
5901
  };
5887
5902
  };
5888
- setRakeDbCliRunFn(rakeDbCliWithAdapter, (x) => x);
5903
+ setRakeDbCliRunFn(rakeDbCliWithAdapter);
5889
5904
  const runCommand = async (adapters, config, args) => {
5890
5905
  let arg = args[0]?.split(":")[0];
5891
5906
  if (rakeDbAliases[arg]) {