rake-db 2.10.31 → 2.10.33
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 +19 -0
- package/dist/index.js +40 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +40 -14
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -1015,8 +1015,27 @@ type ChangeCallback<CT extends ColumnTypesBase = ColumnTypesBase> = (db: DbMigra
|
|
|
1015
1015
|
|
|
1016
1016
|
declare const migrateOrRollback: <CT extends Record<string, orchid_core.AnyColumnTypeCreator>>(options: MaybeArray<AdapterOptions>, config: RakeDbConfig<CT>, args: string[], up: boolean) => Promise<void>;
|
|
1017
1017
|
declare const changeCache: Record<string, ChangeCallback[] | undefined>;
|
|
1018
|
+
/**
|
|
1019
|
+
* Will run all pending yet migrations, sequentially in order,
|
|
1020
|
+
* will apply `change` functions top-to-bottom.
|
|
1021
|
+
*
|
|
1022
|
+
* @param options - options to construct db adapter with
|
|
1023
|
+
* @param config - specifies how to load migrations, may have `appCodeUpdater`, callbacks, and logger.
|
|
1024
|
+
* @param args - pass none or `all` to run all migrations, pass int for how many to migrate, `--code` to enable and `--code false` to disable `useCodeUpdater`.
|
|
1025
|
+
*/
|
|
1018
1026
|
declare const migrate: <CT extends Record<string, orchid_core.AnyColumnTypeCreator>>(options: MaybeArray<AdapterOptions>, config: RakeDbConfig<CT>, args?: string[]) => Promise<void>;
|
|
1027
|
+
/**
|
|
1028
|
+
* Will roll back one latest applied migration,
|
|
1029
|
+
* will apply `change` functions bottom-to-top.
|
|
1030
|
+
*
|
|
1031
|
+
* Takes the same options as {@link migrate}.
|
|
1032
|
+
*/
|
|
1019
1033
|
declare const rollback: <CT extends Record<string, orchid_core.AnyColumnTypeCreator>>(options: MaybeArray<AdapterOptions>, config: RakeDbConfig<CT>, args?: string[]) => Promise<void>;
|
|
1034
|
+
/**
|
|
1035
|
+
* Calls {@link rollback} and then {@link migrate}.
|
|
1036
|
+
*
|
|
1037
|
+
* Takes the same options as {@link migrate}.
|
|
1038
|
+
*/
|
|
1020
1039
|
declare const redo: <CT extends Record<string, orchid_core.AnyColumnTypeCreator>>(options: MaybeArray<AdapterOptions>, config: RakeDbConfig<CT>, args?: string[]) => Promise<void>;
|
|
1021
1040
|
|
|
1022
1041
|
declare const rakeDb: <CT extends Record<string, orchid_core.AnyColumnTypeCreator> = {
|
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 (
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
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 .
|
|
280
|
+
`Only .ts, .js, and .mjs files are supported for migration, received: ${path}`
|
|
259
281
|
);
|
|
260
282
|
}
|
|
261
283
|
}
|
|
@@ -2311,7 +2333,11 @@ const processMigration = async (db, up, file, config, options, appCodeUpdaterCac
|
|
|
2311
2333
|
const migrate = (options, config, args = []) => migrateOrRollback(options, config, args, true);
|
|
2312
2334
|
const rollback = (options, config, args = []) => migrateOrRollback(options, config, args, false);
|
|
2313
2335
|
const redo = async (options, config, args = []) => {
|
|
2336
|
+
var _a;
|
|
2314
2337
|
await migrateOrRollback(options, config, args, false);
|
|
2338
|
+
for (const file in changeCache) {
|
|
2339
|
+
(_a = changeCache[file]) == null ? void 0 : _a.reverse();
|
|
2340
|
+
}
|
|
2315
2341
|
await migrateOrRollback(options, config, args, true);
|
|
2316
2342
|
};
|
|
2317
2343
|
|