rake-db 2.12.7 → 2.14.0
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 +56 -52
- package/dist/index.js +27 -17
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +27 -18
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -2203,6 +2203,8 @@ const removeMigratedVersion = async (db, version, config) => {
|
|
|
2203
2203
|
})} WHERE version = '${version}'`
|
|
2204
2204
|
);
|
|
2205
2205
|
};
|
|
2206
|
+
class NoMigrationsTableError extends Error {
|
|
2207
|
+
}
|
|
2206
2208
|
const getMigratedVersionsMap = async (db, config) => {
|
|
2207
2209
|
try {
|
|
2208
2210
|
const result = await db.arrays(
|
|
@@ -2211,10 +2213,10 @@ const getMigratedVersionsMap = async (db, config) => {
|
|
|
2211
2213
|
return Object.fromEntries(result.rows.map((row) => [row[0], true]));
|
|
2212
2214
|
} catch (err) {
|
|
2213
2215
|
if (err.code === "42P01") {
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
+
throw new NoMigrationsTableError();
|
|
2217
|
+
} else {
|
|
2218
|
+
throw err;
|
|
2216
2219
|
}
|
|
2217
|
-
throw err;
|
|
2218
2220
|
}
|
|
2219
2221
|
};
|
|
2220
2222
|
|
|
@@ -2249,9 +2251,6 @@ function makeMigrateFn(defaultCount, up, fn) {
|
|
|
2249
2251
|
const adapter = new Adapter(opts);
|
|
2250
2252
|
try {
|
|
2251
2253
|
await adapter.transaction(begin, async (trx) => {
|
|
2252
|
-
await trx.query(
|
|
2253
|
-
`SELECT pg_advisory_xact_lock('${RAKE_DB_LOCK_KEY}')`
|
|
2254
|
-
);
|
|
2255
2254
|
await fn(
|
|
2256
2255
|
trx,
|
|
2257
2256
|
conf,
|
|
@@ -2260,6 +2259,16 @@ function makeMigrateFn(defaultCount, up, fn) {
|
|
|
2260
2259
|
localAsts
|
|
2261
2260
|
);
|
|
2262
2261
|
});
|
|
2262
|
+
} catch (err) {
|
|
2263
|
+
if (err instanceof NoMigrationsTableError) {
|
|
2264
|
+
await adapter.transaction(begin, async (trx) => {
|
|
2265
|
+
const config2 = conf;
|
|
2266
|
+
await createSchemaMigrations(trx, config2);
|
|
2267
|
+
await fn(trx, config2, files, count != null ? count : defaultCount, localAsts);
|
|
2268
|
+
});
|
|
2269
|
+
} else {
|
|
2270
|
+
throw err;
|
|
2271
|
+
}
|
|
2263
2272
|
} finally {
|
|
2264
2273
|
await adapter.close();
|
|
2265
2274
|
}
|
|
@@ -2290,7 +2299,7 @@ const redo = makeMigrateFn(
|
|
|
2290
2299
|
async (trx, config, files, count, asts) => {
|
|
2291
2300
|
await migrateOrRollback(trx, config, files, count, asts, false);
|
|
2292
2301
|
files.reverse();
|
|
2293
|
-
await migrateOrRollback(trx, config, files, count, asts, true);
|
|
2302
|
+
await migrateOrRollback(trx, config, files, count, asts, true, true);
|
|
2294
2303
|
files.reverse();
|
|
2295
2304
|
}
|
|
2296
2305
|
);
|
|
@@ -2310,8 +2319,11 @@ function prepareConfig(config, args, count) {
|
|
|
2310
2319
|
delete config.appCodeUpdater;
|
|
2311
2320
|
return config;
|
|
2312
2321
|
}
|
|
2313
|
-
const migrateOrRollback = async (trx, config, files, count, asts, up) => {
|
|
2322
|
+
const migrateOrRollback = async (trx, config, files, count, asts, up, skipLock) => {
|
|
2314
2323
|
var _a, _b, _c;
|
|
2324
|
+
if (!skipLock) {
|
|
2325
|
+
await trx.query(`SELECT pg_advisory_xact_lock('${RAKE_DB_LOCK_KEY}')`);
|
|
2326
|
+
}
|
|
2315
2327
|
let db;
|
|
2316
2328
|
await ((_a = config[up ? "beforeMigrate" : "beforeRollback"]) == null ? void 0 : _a.call(config, db != null ? db : db = getDb(trx)));
|
|
2317
2329
|
const migratedVersions = await getMigratedVersionsMap(trx, config);
|
|
@@ -3247,15 +3259,12 @@ const pushTableAst = (ctx, ast, data, domains, table, pendingTables, innerConstr
|
|
|
3247
3259
|
},
|
|
3248
3260
|
[]
|
|
3249
3261
|
);
|
|
3250
|
-
const columnChecks = innerConstraints.reduce(
|
|
3251
|
-
(
|
|
3252
|
-
|
|
3253
|
-
|
|
3254
|
-
|
|
3255
|
-
|
|
3256
|
-
},
|
|
3257
|
-
{}
|
|
3258
|
-
);
|
|
3262
|
+
const columnChecks = innerConstraints.reduce((acc, item) => {
|
|
3263
|
+
if (belongsToTable(item) && isColumnCheck(item)) {
|
|
3264
|
+
acc[item.check.columns[0]] = item.check.expression;
|
|
3265
|
+
}
|
|
3266
|
+
return acc;
|
|
3267
|
+
}, {});
|
|
3259
3268
|
const shape = makeColumnsShape(
|
|
3260
3269
|
ctx,
|
|
3261
3270
|
data,
|
|
@@ -3908,5 +3917,5 @@ Migrate and rollback common arguments:
|
|
|
3908
3917
|
--code false do not run code updater
|
|
3909
3918
|
`;
|
|
3910
3919
|
|
|
3911
|
-
export { Migration, RAKE_DB_LOCK_KEY, changeCache, createDb, createMigrationInterface, dropDb, generate, getMigratedVersionsMap, makeFileTimeStamp, migrate, migrateOrRollback, rakeDb, redo, removeMigratedVersion, resetDb, rollback, saveMigratedVersion, writeMigrationFile };
|
|
3920
|
+
export { Migration, NoMigrationsTableError, RAKE_DB_LOCK_KEY, changeCache, createDb, createMigrationInterface, dropDb, generate, getMigratedVersionsMap, makeFileTimeStamp, migrate, migrateOrRollback, rakeDb, redo, removeMigratedVersion, resetDb, rollback, saveMigratedVersion, writeMigrationFile };
|
|
3912
3921
|
//# sourceMappingURL=index.mjs.map
|