postgres-schema-migrations 6.0.1 → 6.1.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/migrate.d.ts +3 -1
- package/dist/migrate.js +5 -3
- package/dist/package.json +2 -2
- package/dist/run-migration.js +9 -4
- package/package.json +2 -2
package/dist/migrate.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Config, MigrateDBConfig, Migration } from "./types";
|
|
1
|
+
import { BasicPgClient, Config, MigrateDBConfig, Migration } from "./types";
|
|
2
2
|
/**
|
|
3
3
|
* Run the migrations.
|
|
4
4
|
*
|
|
@@ -11,3 +11,5 @@ import { Config, MigrateDBConfig, Migration } from "./types";
|
|
|
11
11
|
* @returns Details about the migrations which were run
|
|
12
12
|
*/
|
|
13
13
|
export declare function migrate(dbConfig: MigrateDBConfig, migrationsDirectory: string, config?: Config): Promise<Array<Migration>>;
|
|
14
|
+
/** Check whether table exists in postgres - http://stackoverflow.com/a/24089729 */
|
|
15
|
+
export declare function doesTableExist(client: BasicPgClient, tableName: string): Promise<any>;
|
package/dist/migrate.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.migrate = void 0;
|
|
3
|
+
exports.doesTableExist = exports.migrate = void 0;
|
|
4
4
|
const pg = require("pg");
|
|
5
5
|
const sql_template_strings_1 = require("sql-template-strings");
|
|
6
6
|
const create_1 = require("./create");
|
|
@@ -106,8 +106,9 @@ function runMigrations(intendedMigrations, log, schemaName = "public") {
|
|
|
106
106
|
return completedMigrations;
|
|
107
107
|
}
|
|
108
108
|
catch (e) {
|
|
109
|
-
const
|
|
110
|
-
error
|
|
109
|
+
const exception = e;
|
|
110
|
+
const error = new Error(`Migration failed. Reason: ${exception.message}`);
|
|
111
|
+
error.cause = exception.message;
|
|
111
112
|
throw error;
|
|
112
113
|
}
|
|
113
114
|
};
|
|
@@ -156,3 +157,4 @@ async function doesTableExist(client, tableName) {
|
|
|
156
157
|
`);
|
|
157
158
|
return result.rows.length > 0 && result.rows[0].exists;
|
|
158
159
|
}
|
|
160
|
+
exports.doesTableExist = doesTableExist;
|
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "postgres-schema-migrations",
|
|
3
|
-
"version": "6.0
|
|
3
|
+
"version": "6.1.0",
|
|
4
4
|
"description": "Stack Overflow style database migrations for PostgreSQL",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
},
|
|
32
32
|
"scripts": {
|
|
33
33
|
"checkPushed": "[ \"$(git rev-list --count @{upstream}..HEAD)\" -eq 0 ] || (echo You have unpushed commits && exit 1)",
|
|
34
|
-
"prepublishOnly": "npm run checkPushed && npm
|
|
34
|
+
"prepublishOnly": "npm run checkPushed && npm run build",
|
|
35
35
|
"check-formatting": "./node_modules/.bin/prettier '**/*.ts' --list-different",
|
|
36
36
|
"fix-formatting": "./node_modules/.bin/prettier '**/*.ts' --write",
|
|
37
37
|
"lint": "npm run tslint && npm run check-formatting",
|
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) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "postgres-schema-migrations",
|
|
3
|
-
"version": "6.0
|
|
3
|
+
"version": "6.1.0",
|
|
4
4
|
"description": "Stack Overflow style database migrations for PostgreSQL",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
},
|
|
32
32
|
"scripts": {
|
|
33
33
|
"checkPushed": "[ \"$(git rev-list --count @{upstream}..HEAD)\" -eq 0 ] || (echo You have unpushed commits && exit 1)",
|
|
34
|
-
"prepublishOnly": "npm run checkPushed && npm
|
|
34
|
+
"prepublishOnly": "npm run checkPushed && npm run build",
|
|
35
35
|
"check-formatting": "./node_modules/.bin/prettier '**/*.ts' --list-different",
|
|
36
36
|
"fix-formatting": "./node_modules/.bin/prettier '**/*.ts' --write",
|
|
37
37
|
"lint": "npm run tslint && npm run check-formatting",
|