rake-db 2.15.2 → 2.15.4
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 +13 -9
- package/dist/index.js +165 -78
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +165 -78
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as pqb from 'pqb';
|
|
2
2
|
import { ColumnsShape, Db as Db$1, ColumnType, EnumColumn, raw, Adapter, IndexColumnOptions, IndexOptions, ForeignKeyOptions, DbResult, TransactionAdapter, QueryLogObject, TextColumn, TableData, NoPrimaryKeyOption, SingleColumnIndexOptions, DefaultColumnTypes, QueryLogOptions, AdapterOptions } from 'pqb';
|
|
3
|
-
import { EmptyObject, RawSQLBase, ColumnSchemaConfig, MaybeArray, ColumnTypeBase,
|
|
3
|
+
import { EmptyObject, RawSQLBase, ColumnSchemaConfig, MaybeArray, ColumnTypeBase, RecordOptionalString } from 'orchid-core';
|
|
4
4
|
|
|
5
5
|
interface CreateTableResult<Table extends string, Shape extends ColumnsShape> {
|
|
6
6
|
table: Db$1<Table, Shape>;
|
|
@@ -1066,6 +1066,16 @@ declare const generateTimeStamp: () => string;
|
|
|
1066
1066
|
|
|
1067
1067
|
type ChangeCallback<CT extends RakeDbColumnTypes> = (db: DbMigration<CT>, up: boolean) => Promise<void>;
|
|
1068
1068
|
|
|
1069
|
+
declare const saveMigratedVersion: <SchemaConfig extends ColumnSchemaConfig, CT>(db: SilentQueries, version: string, name: string, config: RakeDbConfig<SchemaConfig, CT>) => Promise<void>;
|
|
1070
|
+
declare const deleteMigratedVersion: <SchemaConfig extends ColumnSchemaConfig, CT>(db: SilentQueries, version: string, name: string, config: RakeDbConfig<SchemaConfig, CT>) => Promise<void>;
|
|
1071
|
+
declare class NoMigrationsTableError extends Error {
|
|
1072
|
+
}
|
|
1073
|
+
type RakeDbAppliedVersions = {
|
|
1074
|
+
map: RecordOptionalString;
|
|
1075
|
+
sequence: number[];
|
|
1076
|
+
};
|
|
1077
|
+
declare const getMigratedVersionsMap: <SchemaConfig extends ColumnSchemaConfig, CT>(ctx: RakeDbCtx, adapter: Adapter | TransactionAdapter, config: RakeDbConfig<SchemaConfig, CT>, renameTo?: RakeDbMigrationId) => Promise<RakeDbAppliedVersions>;
|
|
1078
|
+
|
|
1069
1079
|
declare const RAKE_DB_LOCK_KEY = "8582141715823621641";
|
|
1070
1080
|
type MigrateFn = <SchemaConfig extends ColumnSchemaConfig, CT extends RakeDbColumnTypes>(ctx: RakeDbCtx, options: MaybeArray<AdapterOptions>, config: RakeDbConfig<SchemaConfig, CT>, args?: string[]) => Promise<void>;
|
|
1071
1081
|
/**
|
|
@@ -1090,7 +1100,7 @@ declare const rollback: MigrateFn;
|
|
|
1090
1100
|
* Takes the same options as {@link migrate}.
|
|
1091
1101
|
*/
|
|
1092
1102
|
declare const redo: MigrateFn;
|
|
1093
|
-
declare const migrateOrRollback: (
|
|
1103
|
+
declare const migrateOrRollback: (trx: TransactionAdapter, config: RakeDbConfig<ColumnSchemaConfig, RakeDbColumnTypes>, set: MigrationsSet, versions: RakeDbAppliedVersions, count: number, asts: RakeDbAst[], up: boolean, force?: boolean, skipLock?: boolean) => Promise<void>;
|
|
1094
1104
|
declare const changeCache: Record<string, ChangeCallback<RakeDbColumnTypes>[] | undefined>;
|
|
1095
1105
|
|
|
1096
1106
|
/**
|
|
@@ -1131,10 +1141,4 @@ type RakeDbChangeFn<CT extends RakeDbColumnTypes> = (fn: ChangeCallback<CT>) =>
|
|
|
1131
1141
|
*/
|
|
1132
1142
|
declare const rakeDb: RakeDbFn;
|
|
1133
1143
|
|
|
1134
|
-
|
|
1135
|
-
declare const removeMigratedVersion: <SchemaConfig extends ColumnSchemaConfig, CT>(db: SilentQueries, version: string, name: string, config: RakeDbConfig<SchemaConfig, CT>) => Promise<void>;
|
|
1136
|
-
declare class NoMigrationsTableError extends Error {
|
|
1137
|
-
}
|
|
1138
|
-
declare const getMigratedVersionsMap: <SchemaConfig extends ColumnSchemaConfig, CT>(ctx: RakeDbCtx, adapter: Adapter | TransactionAdapter, config: RakeDbConfig<SchemaConfig, CT>) => Promise<RecordString>;
|
|
1139
|
-
|
|
1140
|
-
export { AnyRakeDbConfig, AppCodeUpdater, AppCodeUpdaterParams, ChangeTableCallback, ChangeTableOptions, ColumnComment, ColumnsShapeCallback, ConstraintArg, DbMigration, DropMode, InputRakeDbConfig, Migration, MigrationColumnTypes, ModuleExportsRecord, NoMigrationsTableError, RAKE_DB_LOCK_KEY, RakeDbAst, RakeDbBaseTable, RakeDbColumnTypes, RakeDbConfig, RakeDbMigrationId, SilentQueries, TableOptions, changeCache, createDb, createMigrationInterface, dropDb, generate, generateTimeStamp, getDatabaseAndUserFromOptions, getMigratedVersionsMap, makeFileVersion, migrate, migrateOrRollback, migrationConfigDefaults, processRakeDbConfig, rakeDb, redo, removeMigratedVersion, resetDb, rollback, saveMigratedVersion, writeMigrationFile };
|
|
1144
|
+
export { AnyRakeDbConfig, AppCodeUpdater, AppCodeUpdaterParams, ChangeTableCallback, ChangeTableOptions, ColumnComment, ColumnsShapeCallback, ConstraintArg, DbMigration, DropMode, InputRakeDbConfig, Migration, MigrationColumnTypes, ModuleExportsRecord, NoMigrationsTableError, RAKE_DB_LOCK_KEY, RakeDbAppliedVersions, RakeDbAst, RakeDbBaseTable, RakeDbColumnTypes, RakeDbConfig, RakeDbMigrationId, SilentQueries, TableOptions, changeCache, createDb, createMigrationInterface, deleteMigratedVersion, dropDb, generate, generateTimeStamp, getDatabaseAndUserFromOptions, getMigratedVersionsMap, makeFileVersion, migrate, migrateOrRollback, migrationConfigDefaults, processRakeDbConfig, rakeDb, redo, resetDb, rollback, saveMigratedVersion, writeMigrationFile };
|
package/dist/index.js
CHANGED
|
@@ -2237,7 +2237,7 @@ const saveMigratedVersion = async (db, version, name, config) => {
|
|
|
2237
2237
|
values: [version, name]
|
|
2238
2238
|
});
|
|
2239
2239
|
};
|
|
2240
|
-
const
|
|
2240
|
+
const deleteMigratedVersion = async (db, version, name, config) => {
|
|
2241
2241
|
const res = await db.silentArrays({
|
|
2242
2242
|
text: `DELETE FROM ${quoteWithSchema({
|
|
2243
2243
|
name: config.migrationsTable
|
|
@@ -2250,13 +2250,13 @@ const removeMigratedVersion = async (db, version, name, config) => {
|
|
|
2250
2250
|
};
|
|
2251
2251
|
class NoMigrationsTableError extends Error {
|
|
2252
2252
|
}
|
|
2253
|
-
const getMigratedVersionsMap = async (ctx, adapter, config) => {
|
|
2253
|
+
const getMigratedVersionsMap = async (ctx, adapter, config, renameTo) => {
|
|
2254
2254
|
try {
|
|
2255
2255
|
const table = quoteWithSchema({
|
|
2256
2256
|
name: config.migrationsTable
|
|
2257
2257
|
});
|
|
2258
2258
|
const result = await adapter.arrays(
|
|
2259
|
-
`SELECT * FROM ${table}`
|
|
2259
|
+
`SELECT * FROM ${table} ORDER BY version`
|
|
2260
2260
|
);
|
|
2261
2261
|
if (!result.fields[1]) {
|
|
2262
2262
|
const { migrations } = await getMigrations(ctx, config, true);
|
|
@@ -2288,7 +2288,11 @@ const getMigratedVersionsMap = async (ctx, adapter, config) => {
|
|
|
2288
2288
|
`ALTER TABLE ${table} ALTER COLUMN name SET NOT NULL`
|
|
2289
2289
|
);
|
|
2290
2290
|
}
|
|
2291
|
-
|
|
2291
|
+
let versions = Object.fromEntries(result.rows);
|
|
2292
|
+
if (renameTo) {
|
|
2293
|
+
versions = await renameMigrations(config, adapter, versions, renameTo);
|
|
2294
|
+
}
|
|
2295
|
+
return { map: versions, sequence: result.rows.map((row) => +row[0]) };
|
|
2292
2296
|
} catch (err) {
|
|
2293
2297
|
if (err.code === "42P01") {
|
|
2294
2298
|
throw new NoMigrationsTableError();
|
|
@@ -2297,6 +2301,47 @@ const getMigratedVersionsMap = async (ctx, adapter, config) => {
|
|
|
2297
2301
|
}
|
|
2298
2302
|
}
|
|
2299
2303
|
};
|
|
2304
|
+
async function renameMigrations(config, trx, versions, renameTo) {
|
|
2305
|
+
let first;
|
|
2306
|
+
for (const version in versions) {
|
|
2307
|
+
first = version;
|
|
2308
|
+
break;
|
|
2309
|
+
}
|
|
2310
|
+
if (!first || getMigrationVersion(config, first))
|
|
2311
|
+
return versions;
|
|
2312
|
+
const fileName = fileNamesToChangeMigrationId[renameTo];
|
|
2313
|
+
const filePath = path.join(config.migrationsPath, fileName);
|
|
2314
|
+
const json = await fs.readFile(filePath, "utf-8");
|
|
2315
|
+
let data;
|
|
2316
|
+
try {
|
|
2317
|
+
data = JSON.parse(json);
|
|
2318
|
+
if (typeof data !== "object")
|
|
2319
|
+
throw new Error("Config for renaming is not an object");
|
|
2320
|
+
} catch (err) {
|
|
2321
|
+
throw new Error(`Failed to read ${node_url.pathToFileURL(filePath)}`, {
|
|
2322
|
+
cause: err
|
|
2323
|
+
});
|
|
2324
|
+
}
|
|
2325
|
+
const values = [];
|
|
2326
|
+
const updatedVersions = {};
|
|
2327
|
+
for (const version in versions) {
|
|
2328
|
+
const name = versions[version];
|
|
2329
|
+
const key = `${version}_${name}`;
|
|
2330
|
+
let newVersion = data[key];
|
|
2331
|
+
if (!newVersion) {
|
|
2332
|
+
throw new Error(
|
|
2333
|
+
`Failed to find an entry for the migrated ${key} in the ${fileName} config`
|
|
2334
|
+
);
|
|
2335
|
+
}
|
|
2336
|
+
if (renameTo === "serial") {
|
|
2337
|
+
newVersion = String(newVersion).padStart(4, "0");
|
|
2338
|
+
}
|
|
2339
|
+
updatedVersions[newVersion] = name;
|
|
2340
|
+
values.push([version, name, newVersion]);
|
|
2341
|
+
}
|
|
2342
|
+
await renameMigrationVersionsInDb(config, trx, values);
|
|
2343
|
+
return updatedVersions;
|
|
2344
|
+
}
|
|
2300
2345
|
|
|
2301
2346
|
const createMigrationsTable = async (db, config) => {
|
|
2302
2347
|
var _a, _b, _c;
|
|
@@ -2347,8 +2392,17 @@ const RAKE_DB_LOCK_KEY = "8582141715823621641";
|
|
|
2347
2392
|
function makeMigrateFn(defaultCount, up, fn) {
|
|
2348
2393
|
return async (ctx, options, config, args = []) => {
|
|
2349
2394
|
const set = await getMigrations(ctx, config, up);
|
|
2350
|
-
const
|
|
2351
|
-
|
|
2395
|
+
const arg = args[0];
|
|
2396
|
+
let force = arg === "force";
|
|
2397
|
+
let count;
|
|
2398
|
+
if (arg === "force") {
|
|
2399
|
+
force = true;
|
|
2400
|
+
} else {
|
|
2401
|
+
force = false;
|
|
2402
|
+
const num = arg === "all" ? Infinity : parseInt(arg);
|
|
2403
|
+
count = isNaN(num) ? void 0 : num;
|
|
2404
|
+
}
|
|
2405
|
+
const conf = prepareConfig(config, args, count === void 0 || force);
|
|
2352
2406
|
const asts = [];
|
|
2353
2407
|
const appCodeUpdaterCache = {};
|
|
2354
2408
|
const { appCodeUpdater } = conf;
|
|
@@ -2358,13 +2412,20 @@ function makeMigrateFn(defaultCount, up, fn) {
|
|
|
2358
2412
|
const adapter = new pqb.Adapter(opts);
|
|
2359
2413
|
try {
|
|
2360
2414
|
await transaction(adapter, async (trx) => {
|
|
2361
|
-
await
|
|
2415
|
+
const versions = await getMigratedVersionsMap(
|
|
2362
2416
|
ctx,
|
|
2417
|
+
trx,
|
|
2418
|
+
config,
|
|
2419
|
+
set.renameTo
|
|
2420
|
+
);
|
|
2421
|
+
await fn(
|
|
2363
2422
|
trx,
|
|
2364
2423
|
conf,
|
|
2365
2424
|
set,
|
|
2425
|
+
versions,
|
|
2366
2426
|
count != null ? count : defaultCount,
|
|
2367
|
-
localAsts
|
|
2427
|
+
localAsts,
|
|
2428
|
+
force
|
|
2368
2429
|
);
|
|
2369
2430
|
});
|
|
2370
2431
|
} catch (err) {
|
|
@@ -2372,7 +2433,21 @@ function makeMigrateFn(defaultCount, up, fn) {
|
|
|
2372
2433
|
await transaction(adapter, async (trx) => {
|
|
2373
2434
|
const config2 = conf;
|
|
2374
2435
|
await createMigrationsTable(trx, config2);
|
|
2375
|
-
|
|
2436
|
+
const versions = await getMigratedVersionsMap(
|
|
2437
|
+
ctx,
|
|
2438
|
+
trx,
|
|
2439
|
+
config2,
|
|
2440
|
+
set.renameTo
|
|
2441
|
+
);
|
|
2442
|
+
await fn(
|
|
2443
|
+
trx,
|
|
2444
|
+
config2,
|
|
2445
|
+
set,
|
|
2446
|
+
versions,
|
|
2447
|
+
count != null ? count : defaultCount,
|
|
2448
|
+
localAsts,
|
|
2449
|
+
force
|
|
2450
|
+
);
|
|
2376
2451
|
});
|
|
2377
2452
|
} else {
|
|
2378
2453
|
throw err;
|
|
@@ -2394,31 +2469,37 @@ function makeMigrateFn(defaultCount, up, fn) {
|
|
|
2394
2469
|
const migrate = makeMigrateFn(
|
|
2395
2470
|
Infinity,
|
|
2396
2471
|
true,
|
|
2397
|
-
(
|
|
2472
|
+
(trx, config, set, versions, count, asts, force) => migrateOrRollback(trx, config, set, versions, count, asts, true, force)
|
|
2398
2473
|
);
|
|
2399
2474
|
const rollback = makeMigrateFn(
|
|
2400
2475
|
1,
|
|
2401
2476
|
false,
|
|
2402
|
-
(
|
|
2477
|
+
(trx, config, set, versions, count, asts, force) => migrateOrRollback(trx, config, set, versions, count, asts, false, force)
|
|
2403
2478
|
);
|
|
2404
2479
|
const redo = makeMigrateFn(
|
|
2405
2480
|
1,
|
|
2406
2481
|
true,
|
|
2407
|
-
async (
|
|
2482
|
+
async (trx, config, set, versions, count, asts, force) => {
|
|
2408
2483
|
set.migrations.reverse();
|
|
2409
|
-
await migrateOrRollback(
|
|
2484
|
+
await migrateOrRollback(trx, config, set, versions, count, asts, false);
|
|
2410
2485
|
set.migrations.reverse();
|
|
2411
|
-
await migrateOrRollback(
|
|
2486
|
+
await migrateOrRollback(
|
|
2487
|
+
trx,
|
|
2488
|
+
config,
|
|
2489
|
+
set,
|
|
2490
|
+
versions,
|
|
2491
|
+
count,
|
|
2492
|
+
asts,
|
|
2493
|
+
true,
|
|
2494
|
+
force,
|
|
2495
|
+
true
|
|
2496
|
+
);
|
|
2412
2497
|
}
|
|
2413
2498
|
);
|
|
2414
2499
|
const getDb = (adapter) => pqb.createDb({ adapter });
|
|
2415
|
-
|
|
2416
|
-
const num = args[0] === "all" ? Infinity : parseInt(args[0]);
|
|
2417
|
-
return isNaN(num) ? void 0 : num;
|
|
2418
|
-
};
|
|
2419
|
-
function prepareConfig(config, args, count) {
|
|
2500
|
+
function prepareConfig(config, args, hasArg) {
|
|
2420
2501
|
config = __spreadValues$5({}, config);
|
|
2421
|
-
const i =
|
|
2502
|
+
const i = hasArg ? 0 : 1;
|
|
2422
2503
|
const arg = args[i];
|
|
2423
2504
|
if (arg === "--code") {
|
|
2424
2505
|
config.useCodeUpdater = args[i + 1] !== "false";
|
|
@@ -2427,75 +2508,79 @@ function prepareConfig(config, args, count) {
|
|
|
2427
2508
|
delete config.appCodeUpdater;
|
|
2428
2509
|
return config;
|
|
2429
2510
|
}
|
|
2430
|
-
const migrateOrRollback = async (
|
|
2511
|
+
const migrateOrRollback = async (trx, config, set, versions, count, asts, up, force, skipLock) => {
|
|
2431
2512
|
var _a, _b, _c;
|
|
2513
|
+
const { sequence, map: versionsMap } = versions;
|
|
2514
|
+
if (up) {
|
|
2515
|
+
const rollbackTo = checkMigrationOrder(set, versions, force);
|
|
2516
|
+
if (rollbackTo) {
|
|
2517
|
+
let i = sequence.length - 1;
|
|
2518
|
+
for (; i >= 0; i--) {
|
|
2519
|
+
if (rollbackTo >= sequence[i]) {
|
|
2520
|
+
i++;
|
|
2521
|
+
break;
|
|
2522
|
+
}
|
|
2523
|
+
}
|
|
2524
|
+
if (i < 0)
|
|
2525
|
+
i = 0;
|
|
2526
|
+
set.migrations.reverse();
|
|
2527
|
+
await migrateOrRollback(
|
|
2528
|
+
trx,
|
|
2529
|
+
config,
|
|
2530
|
+
set,
|
|
2531
|
+
versions,
|
|
2532
|
+
sequence.length - i,
|
|
2533
|
+
asts,
|
|
2534
|
+
false
|
|
2535
|
+
);
|
|
2536
|
+
set.migrations.reverse();
|
|
2537
|
+
}
|
|
2538
|
+
}
|
|
2432
2539
|
if (!skipLock)
|
|
2433
2540
|
await queryLock(trx);
|
|
2434
2541
|
let db;
|
|
2435
2542
|
await ((_a = config[up ? "beforeMigrate" : "beforeRollback"]) == null ? void 0 : _a.call(config, db != null ? db : db = getDb(trx)));
|
|
2436
|
-
let migratedVersions = await getMigratedVersionsMap(ctx, trx, config);
|
|
2437
|
-
if (set.renameTo) {
|
|
2438
|
-
migratedVersions = await renameMigrations(
|
|
2439
|
-
config,
|
|
2440
|
-
trx,
|
|
2441
|
-
migratedVersions,
|
|
2442
|
-
set.renameTo
|
|
2443
|
-
);
|
|
2444
|
-
}
|
|
2445
2543
|
for (const file of set.migrations) {
|
|
2446
|
-
if (up &&
|
|
2544
|
+
if (up && versionsMap[file.version] || !up && !versionsMap[file.version]) {
|
|
2447
2545
|
continue;
|
|
2448
2546
|
}
|
|
2449
2547
|
if (count-- <= 0)
|
|
2450
2548
|
break;
|
|
2451
2549
|
await runMigration(trx, up, file, config, asts);
|
|
2550
|
+
if (up) {
|
|
2551
|
+
const name = path.basename(file.path);
|
|
2552
|
+
versionsMap[file.version] = name;
|
|
2553
|
+
sequence.push(+file.version);
|
|
2554
|
+
} else {
|
|
2555
|
+
versionsMap[file.version] = void 0;
|
|
2556
|
+
sequence.pop();
|
|
2557
|
+
}
|
|
2452
2558
|
(_b = config.logger) == null ? void 0 : _b.log(
|
|
2453
2559
|
`${up ? "Migrated" : "Rolled back"} ${orchidCore.pathToLog(file.path)}`
|
|
2454
2560
|
);
|
|
2455
2561
|
}
|
|
2456
2562
|
await ((_c = config[up ? "afterMigrate" : "afterRollback"]) == null ? void 0 : _c.call(config, db != null ? db : db = getDb(trx)));
|
|
2457
2563
|
};
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
} catch (err) {
|
|
2475
|
-
throw new Error(`Failed to read ${node_url.pathToFileURL(filePath)}`, {
|
|
2476
|
-
cause: err
|
|
2477
|
-
});
|
|
2478
|
-
}
|
|
2479
|
-
const values = [];
|
|
2480
|
-
const updatedVersions = {};
|
|
2481
|
-
for (const version in migratedVersions) {
|
|
2482
|
-
const name = migratedVersions[version];
|
|
2483
|
-
const key = `${version}_${name}`;
|
|
2484
|
-
let newVersion = data[key];
|
|
2485
|
-
if (!newVersion) {
|
|
2486
|
-
throw new Error(
|
|
2487
|
-
`Failed to find an entry for the migrated ${key} in the ${fileName} config`
|
|
2488
|
-
);
|
|
2489
|
-
}
|
|
2490
|
-
if (renameTo === "serial") {
|
|
2491
|
-
newVersion = String(newVersion).padStart(4, "0");
|
|
2564
|
+
const checkMigrationOrder = (set, { sequence, map }, force) => {
|
|
2565
|
+
const last = sequence[sequence.length - 1];
|
|
2566
|
+
if (last) {
|
|
2567
|
+
for (const file of set.migrations) {
|
|
2568
|
+
const version = +file.version;
|
|
2569
|
+
if (version > last || map[version])
|
|
2570
|
+
continue;
|
|
2571
|
+
if (!force) {
|
|
2572
|
+
throw new Error(
|
|
2573
|
+
`Cannot migrate ${path.basename(
|
|
2574
|
+
file.path
|
|
2575
|
+
)} because the higher position ${map[last]} was already migrated.
|
|
2576
|
+
Run \`**db command** up force\` to rollback the above migrations and migrate all`
|
|
2577
|
+
);
|
|
2578
|
+
}
|
|
2579
|
+
return version;
|
|
2492
2580
|
}
|
|
2493
|
-
updatedVersions[newVersion] = name;
|
|
2494
|
-
values.push([version, name, newVersion]);
|
|
2495
2581
|
}
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
}
|
|
2582
|
+
return;
|
|
2583
|
+
};
|
|
2499
2584
|
async function runCodeUpdaterAfterAll(options, config, appCodeUpdater, asts, cache) {
|
|
2500
2585
|
for (const ast of asts) {
|
|
2501
2586
|
await (appCodeUpdater == null ? void 0 : appCodeUpdater.process({
|
|
@@ -2543,7 +2628,7 @@ const runMigration = async (trx, up, file, config, asts) => {
|
|
|
2543
2628
|
await changes[i](db, up);
|
|
2544
2629
|
}
|
|
2545
2630
|
}
|
|
2546
|
-
await (up ? saveMigratedVersion :
|
|
2631
|
+
await (up ? saveMigratedVersion : deleteMigratedVersion)(
|
|
2547
2632
|
db.adapter,
|
|
2548
2633
|
file.version,
|
|
2549
2634
|
path.basename(file.path).slice(file.version.length + 1),
|
|
@@ -4035,7 +4120,7 @@ const listMigrationsStatuses = async (options, config, args) => {
|
|
|
4035
4120
|
let maxNameLength = 4;
|
|
4036
4121
|
for (let i = 0; i < options.length; i++) {
|
|
4037
4122
|
const list = migrated[i];
|
|
4038
|
-
const key = Object.entries(list).map(([version, up]) => `${version}${up ? "t" : "f"}`).join("");
|
|
4123
|
+
const key = Object.entries(list.map).map(([version, up]) => `${version}${up ? "t" : "f"}`).join("");
|
|
4039
4124
|
const database = options[i].database || new URL(options[i].databaseURL).pathname.slice(1);
|
|
4040
4125
|
if (map[key]) {
|
|
4041
4126
|
map[key].databases.push(database);
|
|
@@ -4055,7 +4140,7 @@ const listMigrationsStatuses = async (options, config, args) => {
|
|
|
4055
4140
|
maxNameLength = name.length;
|
|
4056
4141
|
}
|
|
4057
4142
|
return {
|
|
4058
|
-
up: !!list[item.version],
|
|
4143
|
+
up: !!list.map[item.version],
|
|
4059
4144
|
version: item.version,
|
|
4060
4145
|
name,
|
|
4061
4146
|
url: node_url.pathToFileURL(item.path)
|
|
@@ -4161,8 +4246,8 @@ const rebase = async (options, config) => {
|
|
|
4161
4246
|
if (start === -1)
|
|
4162
4247
|
return;
|
|
4163
4248
|
const combinedVersionsMap = {};
|
|
4164
|
-
for (const
|
|
4165
|
-
Object.assign(combinedVersionsMap, map);
|
|
4249
|
+
for (const versions of versionMaps) {
|
|
4250
|
+
Object.assign(combinedVersionsMap, versions.map);
|
|
4166
4251
|
}
|
|
4167
4252
|
const renames = [];
|
|
4168
4253
|
const renamesMap = {};
|
|
@@ -4398,13 +4483,15 @@ Commands:
|
|
|
4398
4483
|
reset drop, create and migrate databases
|
|
4399
4484
|
pull generate a combined migration for an existing database
|
|
4400
4485
|
new create new migration file, see below
|
|
4401
|
-
migrate
|
|
4402
|
-
|
|
4486
|
+
up migrate pending migrations
|
|
4487
|
+
migrate migrate pending migrations, also run recurrent
|
|
4488
|
+
up|migrate force resolve the case of a non-migrated file in the middle
|
|
4403
4489
|
rollback or down rollback the last migrated
|
|
4404
4490
|
redo rollback and migrate, run recurrent
|
|
4405
4491
|
status or s list migrations statuses
|
|
4406
4492
|
status path or s p list migrations statuses and paths to files
|
|
4407
4493
|
rec or recurrent run recurrent migrations
|
|
4494
|
+
rebase move local migrations below the new ones from upstream
|
|
4408
4495
|
change-ids serial change migrations ids to 4 digit serial
|
|
4409
4496
|
change-ids serial 42 change migrations ids to custom digits serial
|
|
4410
4497
|
change-ids timestamp change migrations ids to timestamps
|
|
@@ -4430,6 +4517,7 @@ exports.RAKE_DB_LOCK_KEY = RAKE_DB_LOCK_KEY;
|
|
|
4430
4517
|
exports.changeCache = changeCache;
|
|
4431
4518
|
exports.createDb = createDb;
|
|
4432
4519
|
exports.createMigrationInterface = createMigrationInterface;
|
|
4520
|
+
exports.deleteMigratedVersion = deleteMigratedVersion;
|
|
4433
4521
|
exports.dropDb = dropDb;
|
|
4434
4522
|
exports.generate = generate;
|
|
4435
4523
|
exports.generateTimeStamp = generateTimeStamp;
|
|
@@ -4442,7 +4530,6 @@ exports.migrationConfigDefaults = migrationConfigDefaults;
|
|
|
4442
4530
|
exports.processRakeDbConfig = processRakeDbConfig;
|
|
4443
4531
|
exports.rakeDb = rakeDb;
|
|
4444
4532
|
exports.redo = redo;
|
|
4445
|
-
exports.removeMigratedVersion = removeMigratedVersion;
|
|
4446
4533
|
exports.resetDb = resetDb;
|
|
4447
4534
|
exports.rollback = rollback;
|
|
4448
4535
|
exports.saveMigratedVersion = saveMigratedVersion;
|