rake-db 2.10.34 → 2.10.36

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.mjs CHANGED
@@ -236,7 +236,7 @@ function getMigrationsFromConfig(config, up) {
236
236
  result.push({
237
237
  path: path.resolve(basePath, key),
238
238
  version: getVersion(path.basename(key)),
239
- change: migrations[key]
239
+ load: migrations[key]
240
240
  });
241
241
  }
242
242
  if (!up)
@@ -259,7 +259,7 @@ async function getMigrationsFromFiles(config, up) {
259
259
  return {
260
260
  path: filePath,
261
261
  version: getVersion(file),
262
- async change() {
262
+ async load() {
263
263
  try {
264
264
  await imp(filePath);
265
265
  } catch (err) {
@@ -2300,8 +2300,14 @@ const processMigration = async (db, up, file, config, options, appCodeUpdaterCac
2300
2300
  clearChanges();
2301
2301
  let changes = changeCache[file.path];
2302
2302
  if (!changes) {
2303
- await file.change();
2304
- changes = getCurrentChanges();
2303
+ const module = await file.load();
2304
+ const exported = (module == null ? void 0 : module.default) && toArray(module.default);
2305
+ if (config.forceDefaultExports && !exported) {
2306
+ throw new RakeDbError(
2307
+ `Missing a default export in ${file.path} migration`
2308
+ );
2309
+ }
2310
+ changes = exported || getCurrentChanges();
2305
2311
  changeCache[file.path] = changes;
2306
2312
  }
2307
2313
  const db2 = createMigrationInterface(tx, up, config);
@@ -3744,50 +3750,57 @@ const readdirRecursive = async (dirPath, cb) => {
3744
3750
 
3745
3751
  const rakeDb = (options, partialConfig = {}, args = process.argv.slice(2)) => {
3746
3752
  const config = processRakeDbConfig(partialConfig);
3747
- const promise = runCommand(options, config, args);
3748
- return Object.assign(
3749
- (fn) => {
3750
- pushChange(fn);
3751
- },
3752
- {
3753
- promise
3754
- }
3755
- );
3756
- };
3757
- const runCommand = async (options, config, args = process.argv.slice(2)) => {
3758
- var _a, _b, _c;
3759
- const arg = (_a = args[0]) == null ? void 0 : _a.split(":")[0];
3760
- try {
3761
- if (arg === "create") {
3762
- await createDb(options, config);
3763
- } else if (arg === "drop") {
3764
- await dropDb(options, config);
3765
- } else if (arg === "reset") {
3766
- await resetDb(options, config);
3767
- } else if (arg === "up" || arg === "migrate") {
3768
- await migrate(options, config, args.slice(1));
3769
- } else if (arg === "down" || arg === "rollback") {
3770
- await rollback(options, config, args.slice(1));
3771
- } else if (arg === "redo") {
3772
- await redo(options, config, args.slice(1));
3773
- } else if (arg === "new") {
3774
- await generate(config, args.slice(1));
3775
- } else if (arg === "pull") {
3776
- await pullDbStructure(toArray(options)[0], config);
3777
- } else if (config.commands[arg]) {
3778
- await config.commands[arg](toArray(options), config, args.slice(1));
3779
- } else if (arg !== "rec" && arg !== "recurrent") {
3780
- (_b = config.logger) == null ? void 0 : _b.log(help);
3781
- }
3782
- if (arg === "migrate" || arg === "rec" || arg === "recurrent" || arg === "redo") {
3783
- await runRecurrentMigrations(options, config);
3784
- }
3785
- } catch (err) {
3753
+ const promise = runCommand(options, config, args).catch((err) => {
3754
+ var _a;
3786
3755
  if (err instanceof RakeDbError) {
3787
- (_c = config.logger) == null ? void 0 : _c.error(err.message);
3756
+ (_a = config.logger) == null ? void 0 : _a.error(err.message);
3788
3757
  process.exit(1);
3789
3758
  }
3790
3759
  throw err;
3760
+ });
3761
+ return Object.assign(change, {
3762
+ promise
3763
+ });
3764
+ };
3765
+ rakeDb.lazy = (options, partialConfig = {}) => {
3766
+ const config = processRakeDbConfig(partialConfig);
3767
+ return {
3768
+ change,
3769
+ run(args) {
3770
+ return runCommand(options, config, args);
3771
+ }
3772
+ };
3773
+ };
3774
+ function change(fn) {
3775
+ pushChange(fn);
3776
+ return fn;
3777
+ }
3778
+ const runCommand = async (options, config, args = process.argv.slice(2)) => {
3779
+ var _a, _b;
3780
+ const arg = (_a = args[0]) == null ? void 0 : _a.split(":")[0];
3781
+ if (arg === "create") {
3782
+ await createDb(options, config);
3783
+ } else if (arg === "drop") {
3784
+ await dropDb(options, config);
3785
+ } else if (arg === "reset") {
3786
+ await resetDb(options, config);
3787
+ } else if (arg === "up" || arg === "migrate") {
3788
+ await migrate(options, config, args.slice(1));
3789
+ } else if (arg === "down" || arg === "rollback") {
3790
+ await rollback(options, config, args.slice(1));
3791
+ } else if (arg === "redo") {
3792
+ await redo(options, config, args.slice(1));
3793
+ } else if (arg === "new") {
3794
+ await generate(config, args.slice(1));
3795
+ } else if (arg === "pull") {
3796
+ await pullDbStructure(toArray(options)[0], config);
3797
+ } else if (config.commands[arg]) {
3798
+ await config.commands[arg](toArray(options), config, args.slice(1));
3799
+ } else if (arg !== "rec" && arg !== "recurrent") {
3800
+ (_b = config.logger) == null ? void 0 : _b.log(help);
3801
+ }
3802
+ if (arg === "migrate" || arg === "rec" || arg === "recurrent" || arg === "redo") {
3803
+ await runRecurrentMigrations(options, config);
3791
3804
  }
3792
3805
  };
3793
3806
  const help = `Usage: rake-db [command] [arguments]