rake-db 2.3.8 → 2.3.10

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
@@ -23,8 +23,9 @@ var __spreadValues$6 = (a, b) => {
23
23
  };
24
24
  var __spreadProps$5 = (a, b) => __defProps$5(a, __getOwnPropDescs$5(b));
25
25
  const migrationConfigDefaults = {
26
- migrationsPath: path.resolve("src", "migrations"),
26
+ migrationsPath: path.resolve("src", "db", "migrations"),
27
27
  migrationsTable: "schemaMigrations",
28
+ commands: {},
28
29
  requireTs: (path2) => import(path2),
29
30
  log: true,
30
31
  logger: console,
@@ -1110,8 +1111,9 @@ var __spreadValues$1 = (a, b) => {
1110
1111
  }
1111
1112
  return a;
1112
1113
  };
1114
+ const getDb = (adapter) => createDb$1({ adapter, columnTypes });
1113
1115
  const migrateOrRollback = async (options, config, args, up) => {
1114
- var _a;
1116
+ var _a, _b, _c, _d, _e;
1115
1117
  config = __spreadValues$1({}, config);
1116
1118
  const files = await getMigrationFiles(config, up);
1117
1119
  let count = up ? Infinity : 1;
@@ -1129,8 +1131,14 @@ const migrateOrRollback = async (options, config, args, up) => {
1129
1131
  delete config.appCodeUpdater;
1130
1132
  const appCodeUpdaterCache = {};
1131
1133
  for (const opts of toArray(options)) {
1132
- const db = new Adapter(opts);
1133
- const migratedVersions = await getMigratedVersionsMap(db, config);
1134
+ const adapter = new Adapter(opts);
1135
+ let db;
1136
+ if (up) {
1137
+ await ((_a = config.beforeMigrate) == null ? void 0 : _a.call(config, db != null ? db : db = getDb(adapter)));
1138
+ } else {
1139
+ await ((_b = config.beforeRollback) == null ? void 0 : _b.call(config, db != null ? db : db = getDb(adapter)));
1140
+ }
1141
+ const migratedVersions = await getMigratedVersionsMap(adapter, config);
1134
1142
  try {
1135
1143
  for (const file of files) {
1136
1144
  if (up && migratedVersions[file.version] || !up && !migratedVersions[file.version]) {
@@ -1138,11 +1146,23 @@ const migrateOrRollback = async (options, config, args, up) => {
1138
1146
  }
1139
1147
  if (count-- <= 0)
1140
1148
  break;
1141
- await processMigration(db, up, file, config, opts, appCodeUpdaterCache);
1142
- (_a = config.logger) == null ? void 0 : _a.log(`${file.path} ${up ? "migrated" : "rolled back"}`);
1149
+ await processMigration(
1150
+ adapter,
1151
+ up,
1152
+ file,
1153
+ config,
1154
+ opts,
1155
+ appCodeUpdaterCache
1156
+ );
1157
+ (_c = config.logger) == null ? void 0 : _c.log(`${file.path} ${up ? "migrated" : "rolled back"}`);
1158
+ }
1159
+ if (up) {
1160
+ await ((_d = config.afterMigrate) == null ? void 0 : _d.call(config, db != null ? db : db = getDb(adapter)));
1161
+ } else {
1162
+ await ((_e = config.afterRollback) == null ? void 0 : _e.call(config, db != null ? db : db = getDb(adapter)));
1143
1163
  }
1144
1164
  } finally {
1145
- await db.close();
1165
+ await adapter.close();
1146
1166
  }
1147
1167
  delete config.appCodeUpdater;
1148
1168
  }
@@ -1915,6 +1935,8 @@ const rakeDb = async (options, partialConfig = {}, args = process.argv.slice(2))
1915
1935
  await generate(config, args.slice(1));
1916
1936
  } else if (command === "pull") {
1917
1937
  await pullDbStructure(toArray(options)[0], config);
1938
+ } else if (config.commands[command]) {
1939
+ await config.commands[command](toArray(options), config, args.slice(1));
1918
1940
  } else {
1919
1941
  printHelp();
1920
1942
  }