postgres-schema-migrations 6.0.1 → 6.0.3
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/package.json +1 -1
- package/dist/run-migration.js +9 -4
- package/package.json +1 -1
package/dist/package.json
CHANGED
package/dist/run-migration.js
CHANGED
|
@@ -5,6 +5,7 @@ const sql_template_strings_1 = require("sql-template-strings");
|
|
|
5
5
|
const noop = () => {
|
|
6
6
|
//
|
|
7
7
|
};
|
|
8
|
+
const asyncNoop = () => Promise.resolve();
|
|
8
9
|
const insertMigration = async (migrationTableName, client, migration, log) => {
|
|
9
10
|
log(`Saving migration to '${migrationTableName}': ${migration.id} | ${migration.name} | ${migration.hash}`);
|
|
10
11
|
const sql = sql_template_strings_1.default `INSERT INTO `
|
|
@@ -16,14 +17,18 @@ const runMigration = (migrationTableName, client, log = noop) => async (migratio
|
|
|
16
17
|
const inTransaction = migration.sql.includes("-- postgres-migrations disable-transaction") ===
|
|
17
18
|
false;
|
|
18
19
|
log(`Running migration in transaction: ${inTransaction}`);
|
|
19
|
-
const begin = inTransaction
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
const begin = inTransaction
|
|
21
|
+
? () => client.query("START TRANSACTION")
|
|
22
|
+
: asyncNoop;
|
|
23
|
+
const end = inTransaction ? () => client.query("COMMIT") : asyncNoop;
|
|
24
|
+
const cleanup = inTransaction ? () => client.query("ROLLBACK") : asyncNoop;
|
|
22
25
|
try {
|
|
23
26
|
await begin();
|
|
24
27
|
await client.query(migration.sql);
|
|
28
|
+
log("Ran migration " + migration.fileName);
|
|
25
29
|
await insertMigration(migrationTableName, client, migration, log);
|
|
26
|
-
|
|
30
|
+
log("inserted migration in migrations table" + migrationTableName);
|
|
31
|
+
end();
|
|
27
32
|
return migration;
|
|
28
33
|
}
|
|
29
34
|
catch (err) {
|