rake-db 2.4.6 → 2.4.7
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 +8 -3
- package/dist/index.js +46 -35
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +43 -36
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1222,6 +1222,36 @@ const queryExists = (db, sql) => {
|
|
|
1222
1222
|
return db.adapter.query(sql).then(({ rowCount }) => rowCount > 0);
|
|
1223
1223
|
};
|
|
1224
1224
|
|
|
1225
|
+
const saveMigratedVersion = async (db, version, config) => {
|
|
1226
|
+
await db.query(
|
|
1227
|
+
`INSERT INTO ${quoteWithSchema({
|
|
1228
|
+
name: config.migrationsTable
|
|
1229
|
+
})} VALUES ('${version}')`
|
|
1230
|
+
);
|
|
1231
|
+
};
|
|
1232
|
+
const removeMigratedVersion = async (db, version, config) => {
|
|
1233
|
+
await db.query(
|
|
1234
|
+
`DELETE FROM ${quoteWithSchema({
|
|
1235
|
+
name: config.migrationsTable
|
|
1236
|
+
})} WHERE version = '${version}'`
|
|
1237
|
+
);
|
|
1238
|
+
};
|
|
1239
|
+
const getMigratedVersionsMap = async (db, config) => {
|
|
1240
|
+
try {
|
|
1241
|
+
const result = await db.arrays(
|
|
1242
|
+
`SELECT *
|
|
1243
|
+
FROM ${quoteWithSchema({ name: config.migrationsTable })}`
|
|
1244
|
+
);
|
|
1245
|
+
return Object.fromEntries(result.rows.map((row) => [row[0], true]));
|
|
1246
|
+
} catch (err) {
|
|
1247
|
+
if (err.code === "42P01") {
|
|
1248
|
+
await createSchemaMigrations(db, config);
|
|
1249
|
+
return {};
|
|
1250
|
+
}
|
|
1251
|
+
throw err;
|
|
1252
|
+
}
|
|
1253
|
+
};
|
|
1254
|
+
|
|
1225
1255
|
var __defProp$1 = Object.defineProperty;
|
|
1226
1256
|
var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
|
|
1227
1257
|
var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
|
|
@@ -1334,34 +1364,6 @@ const processMigration = async (db, up, file, config, options, appCodeUpdaterCac
|
|
|
1334
1364
|
}));
|
|
1335
1365
|
}
|
|
1336
1366
|
};
|
|
1337
|
-
const saveMigratedVersion = async (db, version, config) => {
|
|
1338
|
-
await db.query(
|
|
1339
|
-
`INSERT INTO ${quoteWithSchema({
|
|
1340
|
-
name: config.migrationsTable
|
|
1341
|
-
})} VALUES ('${version}')`
|
|
1342
|
-
);
|
|
1343
|
-
};
|
|
1344
|
-
const removeMigratedVersion = async (db, version, config) => {
|
|
1345
|
-
await db.query(
|
|
1346
|
-
`DELETE FROM ${quoteWithSchema({
|
|
1347
|
-
name: config.migrationsTable
|
|
1348
|
-
})} WHERE version = '${version}'`
|
|
1349
|
-
);
|
|
1350
|
-
};
|
|
1351
|
-
const getMigratedVersionsMap = async (db, config) => {
|
|
1352
|
-
try {
|
|
1353
|
-
const result = await db.arrays(
|
|
1354
|
-
`SELECT * FROM ${quoteWithSchema({ name: config.migrationsTable })}`
|
|
1355
|
-
);
|
|
1356
|
-
return Object.fromEntries(result.rows.map((row) => [row[0], true]));
|
|
1357
|
-
} catch (err) {
|
|
1358
|
-
if (err.code === "42P01") {
|
|
1359
|
-
await createSchemaMigrations(db, config);
|
|
1360
|
-
return {};
|
|
1361
|
-
}
|
|
1362
|
-
throw err;
|
|
1363
|
-
}
|
|
1364
|
-
};
|
|
1365
1367
|
const migrate = (options, config, args = []) => migrateOrRollback(options, config, args, true);
|
|
1366
1368
|
const rollback = (options, config, args = []) => migrateOrRollback(options, config, args, false);
|
|
1367
1369
|
|
|
@@ -1465,13 +1467,10 @@ const resetDb = async (arg, config) => {
|
|
|
1465
1467
|
await migrate(arg, config);
|
|
1466
1468
|
};
|
|
1467
1469
|
|
|
1468
|
-
const writeMigrationFile = async (config, name, content) => {
|
|
1470
|
+
const writeMigrationFile = async (config, version, name, content) => {
|
|
1469
1471
|
var _a;
|
|
1470
1472
|
await mkdir(config.migrationsPath, { recursive: true });
|
|
1471
|
-
const filePath = path.resolve(
|
|
1472
|
-
config.migrationsPath,
|
|
1473
|
-
`${makeFileTimeStamp()}_${name}.ts`
|
|
1474
|
-
);
|
|
1473
|
+
const filePath = path.resolve(config.migrationsPath, `${version}_${name}.ts`);
|
|
1475
1474
|
await writeFile(filePath, content);
|
|
1476
1475
|
(_a = config.logger) == null ? void 0 : _a.log(`Created ${pathToLog(filePath)}`);
|
|
1477
1476
|
};
|
|
@@ -1479,7 +1478,13 @@ const generate = async (config, args) => {
|
|
|
1479
1478
|
const name = args[0];
|
|
1480
1479
|
if (!name)
|
|
1481
1480
|
throw new Error("Migration name is missing");
|
|
1482
|
-
|
|
1481
|
+
const version = makeFileTimeStamp();
|
|
1482
|
+
await writeMigrationFile(
|
|
1483
|
+
config,
|
|
1484
|
+
version,
|
|
1485
|
+
name,
|
|
1486
|
+
makeContent(name, args.slice(1))
|
|
1487
|
+
);
|
|
1483
1488
|
};
|
|
1484
1489
|
const makeFileTimeStamp = () => {
|
|
1485
1490
|
const now = new Date();
|
|
@@ -2265,7 +2270,9 @@ const pullDbStructure = async (options, config) => {
|
|
|
2265
2270
|
const result = astToMigration(config, ast);
|
|
2266
2271
|
if (!result)
|
|
2267
2272
|
return;
|
|
2268
|
-
|
|
2273
|
+
const version = makeFileTimeStamp();
|
|
2274
|
+
await writeMigrationFile(config, version, "pull", result);
|
|
2275
|
+
await saveMigratedVersion(adapter, version, config);
|
|
2269
2276
|
const cache = {};
|
|
2270
2277
|
for (const item of ast) {
|
|
2271
2278
|
await ((_a = config == null ? void 0 : config.appCodeUpdater) == null ? void 0 : _a.call(config, {
|
|
@@ -2346,5 +2353,5 @@ Generate arguments:
|
|
|
2346
2353
|
rake-db g createTable id:serial.primaryKey name:text.nullable
|
|
2347
2354
|
`;
|
|
2348
2355
|
|
|
2349
|
-
export { MigrationBase, change, changeCache, createDb, createMigrationInterface, dropDb, generate, migrate, migrateOrRollback, rakeDb, resetDb, rollback, writeMigrationFile };
|
|
2356
|
+
export { MigrationBase, change, changeCache, createDb, createMigrationInterface, dropDb, generate, getMigratedVersionsMap, makeFileTimeStamp, migrate, migrateOrRollback, rakeDb, removeMigratedVersion, resetDb, rollback, saveMigratedVersion, writeMigrationFile };
|
|
2350
2357
|
//# sourceMappingURL=index.mjs.map
|