rake-db 2.10.32 → 2.10.34

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.js CHANGED
@@ -26,6 +26,18 @@ var __spreadValues$6 = (a, b) => {
26
26
  return a;
27
27
  };
28
28
  var __spreadProps$5 = (a, b) => __defProps$5(a, __getOwnPropDescs$5(b));
29
+ var __objRest$2 = (source, exclude) => {
30
+ var target = {};
31
+ for (var prop in source)
32
+ if (__hasOwnProp$6.call(source, prop) && exclude.indexOf(prop) < 0)
33
+ target[prop] = source[prop];
34
+ if (source != null && __getOwnPropSymbols$6)
35
+ for (var prop of __getOwnPropSymbols$6(source)) {
36
+ if (exclude.indexOf(prop) < 0 && __propIsEnum$6.call(source, prop))
37
+ target[prop] = source[prop];
38
+ }
39
+ return target;
40
+ };
29
41
  const migrationConfigDefaults = {
30
42
  migrationsPath: path.join("src", "db", "migrations"),
31
43
  migrationsTable: "schemaMigrations",
@@ -211,19 +223,29 @@ const getTextAfterTo = (input) => {
211
223
  const getTextAfterFrom = (input) => {
212
224
  return getTextAfterRegExp(input, /(From|-from|_from)[A-Z-_]/, 4);
213
225
  };
214
- const getMigrations = async (config, up) => {
215
- if ("migrations" in config) {
216
- const result = [];
217
- const { migrations, basePath } = config;
218
- for (const key in migrations) {
219
- result.push({
220
- path: path.resolve(basePath, key),
221
- version: getVersion(path.basename(key)),
222
- change: migrations[key]
223
- });
224
- }
225
- return result;
226
+ const getMigrations = async (_a, up) => {
227
+ var _b = _a, {
228
+ migrations
229
+ } = _b, config = __objRest$2(_b, [
230
+ "migrations"
231
+ ]);
232
+ return migrations ? getMigrationsFromConfig(__spreadProps$5(__spreadValues$6({}, config), { migrations }), up) : getMigrationsFromFiles(config, up);
233
+ };
234
+ function getMigrationsFromConfig(config, up) {
235
+ const result = [];
236
+ const { migrations, basePath } = config;
237
+ for (const key in migrations) {
238
+ result.push({
239
+ path: path.resolve(basePath, key),
240
+ version: getVersion(path.basename(key)),
241
+ change: migrations[key]
242
+ });
226
243
  }
244
+ if (!up)
245
+ result.reverse();
246
+ return result;
247
+ }
248
+ async function getMigrationsFromFiles(config, up) {
227
249
  const { migrationsPath, import: imp } = config;
228
250
  let files;
229
251
  try {
@@ -250,12 +272,12 @@ const getMigrations = async (config, up) => {
250
272
  }
251
273
  };
252
274
  });
253
- };
275
+ }
254
276
  function checkExt(filePath) {
255
277
  const ext = path.extname(filePath);
256
278
  if (ext !== ".ts" && ext !== ".js" && ext !== ".mjs") {
257
279
  throw new Error(
258
- `Only .ts and .js files are supported for migration, received: ${path}`
280
+ `Only .ts, .js, and .mjs files are supported for migration, received: ${path}`
259
281
  );
260
282
  }
261
283
  }