Skip to content

Commit 9d4d757

Browse files
committed
Update dependencies
Run `npm update` and `npm audit fix` Fix formatting
1 parent b1bf47b commit 9d4d757

File tree

4 files changed

+89
-96
lines changed

4 files changed

+89
-96
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock.json -diff

package-lock.json

Lines changed: 56 additions & 61 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,23 +50,22 @@
5050
}
5151
},
5252
"dependencies": {
53-
"pg": "^8.5.1",
53+
"pg": "^8.6.0",
5454
"sql-template-strings": "^2.2.2"
5555
},
5656
"devDependencies": {
57-
"@types/bluebird": "^3.5.33",
58-
"@types/node": "^10.17.51",
59-
"@types/pg": "^7.14.8",
60-
"@types/sinon": "^9.0.10",
57+
"@types/node": "^10.17.60",
58+
"@types/pg": "^7.14.11",
59+
"@types/sinon": "^9.0.11",
6160
"ava": "^3.15.0",
6261
"fit-commit-js": "^0.3.2",
6362
"husky": "^3.1.0",
64-
"prettier": "^2.2.1",
65-
"sinon": "^9.2.3",
63+
"prettier": "^2.3.1",
64+
"sinon": "^9.2.4",
6665
"ts-node": "^8.10.2",
6766
"tslint": "^6.1.3",
6867
"tslint-config-prettier": "^1.18.0",
69-
"typescript": "^3.9.7",
68+
"typescript": "^3.9.10",
7069
"typescript-tslint-plugin": "^0.5.5"
7170
}
7271
}

src/run-migration.ts

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -23,38 +23,36 @@ const insertMigration = async (
2323
return client.query(sql)
2424
}
2525

26-
export const runMigration = (
27-
migrationTableName: string,
28-
client: BasicPgClient,
29-
log: Logger = noop,
30-
) => async (migration: Migration) => {
31-
const inTransaction =
32-
migration.sql.includes("-- postgres-migrations disable-transaction") ===
33-
false
34-
35-
log(`Running migration in transaction: ${inTransaction}`)
26+
export const runMigration =
27+
(migrationTableName: string, client: BasicPgClient, log: Logger = noop) =>
28+
async (migration: Migration) => {
29+
const inTransaction =
30+
migration.sql.includes("-- postgres-migrations disable-transaction") ===
31+
false
3632

37-
const begin = inTransaction ? () => client.query("START TRANSACTION") : noop
33+
log(`Running migration in transaction: ${inTransaction}`)
3834

39-
const end = inTransaction ? () => client.query("COMMIT") : noop
35+
const begin = inTransaction ? () => client.query("START TRANSACTION") : noop
4036

41-
const cleanup = inTransaction ? () => client.query("ROLLBACK") : noop
37+
const end = inTransaction ? () => client.query("COMMIT") : noop
4238

43-
try {
44-
await begin()
45-
await client.query(migration.sql)
46-
await insertMigration(migrationTableName, client, migration, log)
47-
await end()
39+
const cleanup = inTransaction ? () => client.query("ROLLBACK") : noop
4840

49-
return migration
50-
} catch (err) {
5141
try {
52-
await cleanup()
53-
} catch {
54-
//
42+
await begin()
43+
await client.query(migration.sql)
44+
await insertMigration(migrationTableName, client, migration, log)
45+
await end()
46+
47+
return migration
48+
} catch (err) {
49+
try {
50+
await cleanup()
51+
} catch {
52+
//
53+
}
54+
throw new Error(
55+
`An error occurred running '${migration.name}'. Rolled back this migration. No further migrations were run. Reason: ${err.message}`,
56+
)
5557
}
56-
throw new Error(
57-
`An error occurred running '${migration.name}'. Rolled back this migration. No further migrations were run. Reason: ${err.message}`,
58-
)
5958
}
60-
}

0 commit comments

Comments
 (0)