From bfdd2a30aaf150a29224f2dabb2b5b845c4e1365 Mon Sep 17 00:00:00 2001 From: Thom Wright Date: Mon, 6 Apr 2020 17:04:29 +0100 Subject: [PATCH] Upgrade prettier --- package-lock.json | 6 +- package.json | 2 +- src/__tests__/create.ts | 36 +++---- src/__tests__/fixtures/docker-postgres.ts | 4 +- src/__tests__/migrate.ts | 116 +++++++++++----------- src/__unit__/file-name-parser/index.ts | 18 ++-- src/__unit__/migration-file/index.ts | 4 +- src/__unit__/run-migration/index.ts | 18 ++-- src/create.ts | 4 +- src/files-loader.ts | 2 +- src/migrate.ts | 2 +- src/migration-file.ts | 5 +- src/with-lock.ts | 2 +- 13 files changed, 108 insertions(+), 111 deletions(-) diff --git a/package-lock.json b/package-lock.json index 8455f4d..d622cb7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2588,9 +2588,9 @@ "dev": true }, "prettier": { - "version": "1.19.1", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-1.19.1.tgz", - "integrity": "sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew==", + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.0.4.tgz", + "integrity": "sha512-SVJIQ51spzFDvh4fIbCLvciiDMCrRhlN3mbZvv/+ycjvmF5E73bKdGfU8QDLNmjYJf+lsGnDBC4UUnvTe5OO0w==", "dev": true }, "pretty-ms": { diff --git a/package.json b/package.json index 886ce99..4590678 100644 --- a/package.json +++ b/package.json @@ -58,7 +58,7 @@ "ava": "^3.6.0", "fit-commit-js": "^0.3.2", "husky": "^3.1.0", - "prettier": "^1.19.1", + "prettier": "^2.0.4", "sinon": "^7.5.0", "ts-node": "^8.8.2", "tslint": "^6.1.1", diff --git a/src/__tests__/create.ts b/src/__tests__/create.ts index 9c956ca..936e51f 100644 --- a/src/__tests__/create.ts +++ b/src/__tests__/create.ts @@ -8,7 +8,7 @@ const CONTAINER_NAME = "pg-migrations-test-create" let port: number -test.before.cb(t => { +test.before.cb((t) => { port = startPostgres(CONTAINER_NAME, t) }) @@ -16,7 +16,7 @@ test.after.always(() => { stopPostgres(CONTAINER_NAME) }) -test("with connected client", async t => { +test("with connected client", async (t) => { t.plan(0) const client = new pg.Client({ @@ -35,7 +35,7 @@ test("with connected client", async t => { } }) -test("successful creation", t => { +test("successful creation", (t) => { t.plan(0) return createDb("create-test-success", { @@ -46,7 +46,7 @@ test("successful creation", t => { }) }) -test("bad arguments - no database name", t => { +test("bad arguments - no database name", (t) => { return t .throwsAsync( // tslint:disable-next-line no-any @@ -57,23 +57,23 @@ test("bad arguments - no database name", t => { port, }), ) - .then(err => { + .then((err) => { t.regex(err.message, /database name/) }) }) -test("bad arguments - empty db config", t => { +test("bad arguments - empty db config", (t) => { return ( t // tslint:disable-next-line no-any .throwsAsync(createDb("create-test-no-config", {} as any)) - .then(err => { + .then((err) => { t.regex(err.message, /config/) }) ) }) -test("bad arguments - incorrect user", t => { +test("bad arguments - incorrect user", (t) => { return t .throwsAsync( createDb("create-test-user", { @@ -83,12 +83,12 @@ test("bad arguments - incorrect user", t => { port, }), ) - .then(err => { + .then((err) => { t.regex(err.message, /nobody/) }) }) -test("bad arguments - incorrect password", t => { +test("bad arguments - incorrect password", (t) => { return t .throwsAsync( createDb("create-test-password", { @@ -98,12 +98,12 @@ test("bad arguments - incorrect password", t => { port, }), ) - .then(err => { + .then((err) => { t.regex(err.message, /password/) }) }) -test("bad arguments - incorrect host", t => { +test("bad arguments - incorrect host", (t) => { return t .throwsAsync( createDb("create-test-host", { @@ -113,12 +113,12 @@ test("bad arguments - incorrect host", t => { port, }), ) - .then(err => { + .then((err) => { t.regex(err.message, /sillyhost/) }) }) -test("bad arguments - incorrect port", t => { +test("bad arguments - incorrect port", (t) => { return t .throwsAsync( createDb("create-test-port", { @@ -128,12 +128,12 @@ test("bad arguments - incorrect port", t => { port: 1234, }), ) - .then(err => { + .then((err) => { t.regex(err.message, /1234/) }) }) -test("already created", t => { +test("already created", (t) => { t.plan(0) const create = () => createDb("create-test-duplicate", { @@ -146,7 +146,7 @@ test("already created", t => { return create().then(create) }) -test("database name included in config", t => { +test("database name included in config", (t) => { t.plan(0) const create = () => createDb("create-test-db-name", { @@ -161,7 +161,7 @@ test("database name included in config", t => { return create().then(create) }) -test("custom default database name", t => { +test("custom default database name", (t) => { t.plan(0) const create = () => createDb("create-test-default-db", { diff --git a/src/__tests__/fixtures/docker-postgres.ts b/src/__tests__/fixtures/docker-postgres.ts index 7131cea..0c83dac 100644 --- a/src/__tests__/fixtures/docker-postgres.ts +++ b/src/__tests__/fixtures/docker-postgres.ts @@ -33,7 +33,7 @@ export const startPostgres = (containerName: string, t: CbExecutionContext) => { "--filter", "event=health_status", ]) - events.stdout.on("data", data => { + events.stdout.on("data", (data) => { const dataString = data.toString() if (dataString.includes("health_status: healthy")) { @@ -42,7 +42,7 @@ export const startPostgres = (containerName: string, t: CbExecutionContext) => { t.end() } }) - events.on("error", err => { + events.on("error", (err) => { console.error("Error in 'docker events' process:", err) events.kill() t.fail(err.message) diff --git a/src/__tests__/migrate.ts b/src/__tests__/migrate.ts index e7fb575..30357c4 100644 --- a/src/__tests__/migrate.ts +++ b/src/__tests__/migrate.ts @@ -9,11 +9,11 @@ const CONTAINER_NAME = "pg-migrations-test-migrate" let port: number -process.on("uncaughtException", function(err) { +process.on("uncaughtException", function (err) { console.log(err) }) -test.before.cb(t => { +test.before.cb((t) => { port = startPostgres(CONTAINER_NAME, t) }) @@ -21,7 +21,7 @@ test.after.always(() => { stopPostgres(CONTAINER_NAME) }) -test("concurrent migrations", async t => { +test("concurrent migrations", async (t) => { const databaseName = "migration-test-concurrent" const dbConfig = { database: databaseName, @@ -46,7 +46,7 @@ test("concurrent migrations", async t => { }) // https://github.com/ThomWright/postgres-migrations/issues/36 -test("concurrent migrations - index concurrently", async t => { +test("concurrent migrations - index concurrently", async (t) => { const databaseName = "migration-test-concurrent-no-tx" const dbConfig = { database: databaseName, @@ -64,10 +64,10 @@ test("concurrent migrations - index concurrently", async t => { // while the other waits for the advisory lock await Promise.all([ migrate(dbConfig, "src/__tests__/fixtures/concurrent-index-2", { - logger: msg => console.log("A", msg), + logger: (msg) => console.log("A", msg), }), migrate(dbConfig, "src/__tests__/fixtures/concurrent-index-2", { - logger: msg => console.log("B", msg), + logger: (msg) => console.log("B", msg), }), ]) @@ -76,7 +76,7 @@ test("concurrent migrations - index concurrently", async t => { }) // can't test with unconnected client because `pg` just hangs on the first query... -test("with connected client", async t => { +test("with connected client", async (t) => { const databaseName = "migration-test-with-connected-client" const dbConfig = { database: databaseName, @@ -114,7 +114,7 @@ test("with connected client", async t => { } }) -test("with pool", async t => { +test("with pool", async (t) => { const databaseName = "migration-test-with-pool" const dbConfig = { database: databaseName, @@ -150,7 +150,7 @@ test("with pool", async t => { } }) -test("with pool client", async t => { +test("with pool client", async (t) => { const databaseName = "migration-test-with-pool-client" const dbConfig = { database: databaseName, @@ -190,7 +190,7 @@ test("with pool client", async t => { } }) -test("successful first migration", t => { +test("successful first migration", (t) => { const databaseName = "migration-test-success-first" const dbConfig = { database: databaseName, @@ -203,12 +203,12 @@ test("successful first migration", t => { return createDb(databaseName, dbConfig) .then(() => migrate(dbConfig, "src/__tests__/fixtures/success-first")) .then(() => doesTableExist(dbConfig, "success")) - .then(exists => { + .then((exists) => { t.truthy(exists) }) }) -test("successful second migration", t => { +test("successful second migration", (t) => { const databaseName = "migration-test-success-second" const dbConfig = { database: databaseName, @@ -222,12 +222,12 @@ test("successful second migration", t => { .then(() => migrate(dbConfig, "src/__tests__/fixtures/success-first")) .then(() => migrate(dbConfig, "src/__tests__/fixtures/success-second")) .then(() => doesTableExist(dbConfig, "more_success")) - .then(exists => { + .then((exists) => { t.truthy(exists) }) }) -test("successful first javascript migration", t => { +test("successful first javascript migration", (t) => { const databaseName = "migration-test-success-js-first" const dbConfig = { database: databaseName, @@ -240,12 +240,12 @@ test("successful first javascript migration", t => { return createDb(databaseName, dbConfig) .then(() => migrate(dbConfig, "src/__tests__/fixtures/success-js-first")) .then(() => doesTableExist(dbConfig, "success")) - .then(exists => { + .then((exists) => { t.truthy(exists) }) }) -test("successful second mixed js and sql migration", t => { +test("successful second mixed js and sql migration", (t) => { const databaseName = "migration-test-success-second-mixed-js-sql" const dbConfig = { database: databaseName, @@ -261,12 +261,12 @@ test("successful second mixed js and sql migration", t => { migrate(dbConfig, "src/__tests__/fixtures/success-second-mixed-js-sql"), ) .then(() => doesTableExist(dbConfig, "more_success")) - .then(exists => { + .then((exists) => { t.truthy(exists) }) }) -test("successful complex js migration", t => { +test("successful complex js migration", (t) => { const databaseName = "migration-test-success-complex-js" const dbConfig = { database: databaseName, @@ -279,19 +279,19 @@ test("successful complex js migration", t => { return createDb(databaseName, dbConfig) .then(() => migrate(dbConfig, "src/__tests__/fixtures/success-complex-js")) .then(() => doesTableExist(dbConfig, "complex")) - .then(exists => { + .then((exists) => { t.truthy(exists) }) }) -test("bad arguments - no db config", t => { +test("bad arguments - no db config", (t) => { // tslint:disable-next-line no-any - return t.throwsAsync((migrate as any)()).then(err => { + return t.throwsAsync((migrate as any)()).then((err) => { t.regex(err.message, /config/) }) }) -test("bad arguments - no migrations directory argument", t => { +test("bad arguments - no migrations directory argument", (t) => { return t .throwsAsync( // tslint:disable-next-line no-any @@ -303,12 +303,12 @@ test("bad arguments - no migrations directory argument", t => { port, }), ) - .then(err => { + .then((err) => { t.regex(err.message, /directory/) }) }) -test("bad arguments - incorrect user", t => { +test("bad arguments - incorrect user", (t) => { return t .throwsAsync( migrate( @@ -322,12 +322,12 @@ test("bad arguments - incorrect user", t => { "src/__tests__/fixtures/empty", ), ) - .then(err => { + .then((err) => { t.regex(err.message, /nobody/) }) }) -test("bad arguments - incorrect password", t => { +test("bad arguments - incorrect password", (t) => { return t .throwsAsync( migrate( @@ -341,12 +341,12 @@ test("bad arguments - incorrect password", t => { "src/__tests__/fixtures/empty", ), ) - .then(err => { + .then((err) => { t.regex(err.message, /password/) }) }) -test("bad arguments - incorrect host", t => { +test("bad arguments - incorrect host", (t) => { return t .throwsAsync( migrate( @@ -360,12 +360,12 @@ test("bad arguments - incorrect host", t => { "src/__tests__/fixtures/empty", ), ) - .then(err => { + .then((err) => { t.regex(err.message, /sillyhost/) }) }) -test("bad arguments - incorrect port", t => { +test("bad arguments - incorrect port", (t) => { return t .throwsAsync( migrate( @@ -379,12 +379,12 @@ test("bad arguments - incorrect port", t => { "src/__tests__/fixtures/empty", ), ) - .then(err => { + .then((err) => { t.regex(err.message, /1234/) }) }) -test("no database", t => { +test("no database", (t) => { return t .throwsAsync( migrate( @@ -398,7 +398,7 @@ test("no database", t => { "src/__tests__/fixtures/empty", ), ) - .then(err => { + .then((err) => { t.regex( err.message, /database "migration-test-no-database" does not exist/, @@ -406,7 +406,7 @@ test("no database", t => { }) }) -test("no migrations dir", t => { +test("no migrations dir", (t) => { const databaseName = "migration-test-no-dir" const dbConfig = { database: databaseName, @@ -420,12 +420,12 @@ test("no migrations dir", t => { return migrate(dbConfig, "not/real/path") }) - return t.throwsAsync(promise).then(err => { + return t.throwsAsync(promise).then((err) => { t.regex(err.message, /not\/real\/path/) }) }) -test("empty migrations dir", async t => { +test("empty migrations dir", async (t) => { t.plan(0) const databaseName = "migration-test-empty-dir" const dbConfig = { @@ -441,7 +441,7 @@ test("empty migrations dir", async t => { }) }) -test("non-consecutive ordering", t => { +test("non-consecutive ordering", (t) => { const databaseName = "migration-test-non-consec" const dbConfig = { database: databaseName, @@ -455,12 +455,12 @@ test("non-consecutive ordering", t => { return migrate(dbConfig, "src/__tests__/fixtures/non-consecutive") }) - return t.throwsAsync(promise).then(err => { + return t.throwsAsync(promise).then((err) => { t.regex(err.message, /Found a non-consecutive migration ID/) }) }) -test("not starting from one", t => { +test("not starting from one", (t) => { const databaseName = "migration-test-starting-id" const dbConfig = { database: databaseName, @@ -474,12 +474,12 @@ test("not starting from one", t => { return migrate(dbConfig, "src/__tests__/fixtures/start-from-2") }) - return t.throwsAsync(promise).then(err => { + return t.throwsAsync(promise).then((err) => { t.regex(err.message, /Found a non-consecutive migration ID/) }) }) -test("negative ID", t => { +test("negative ID", (t) => { const databaseName = "migration-test-negative" const dbConfig = { database: databaseName, @@ -493,13 +493,13 @@ test("negative ID", t => { return migrate(dbConfig, "src/__tests__/fixtures/negative") }) - return t.throwsAsync(promise).then(err => { + return t.throwsAsync(promise).then((err) => { t.regex(err.message, /Found a non-consecutive migration ID/) t.regex(err.message, /-1_negative/, "Should name the problem file") }) }) -test("invalid file name", t => { +test("invalid file name", (t) => { const databaseName = "migration-test-invalid-file-name" const dbConfig = { database: databaseName, @@ -513,13 +513,13 @@ test("invalid file name", t => { return migrate(dbConfig, "src/__tests__/fixtures/invalid-file-name") }) - return t.throwsAsync(promise).then(err => { + return t.throwsAsync(promise).then((err) => { t.regex(err.message, /Invalid file name/) t.regex(err.message, /migrate-this/, "Should name the problem file") }) }) -test("syntax error", t => { +test("syntax error", (t) => { const databaseName = "migration-test-syntax-error" const dbConfig = { database: databaseName, @@ -533,12 +533,12 @@ test("syntax error", t => { return migrate(dbConfig, "src/__tests__/fixtures/syntax-error") }) - return t.throwsAsync(promise).then(err => { + return t.throwsAsync(promise).then((err) => { t.regex(err.message, /syntax error/) }) }) -test("bad javascript file - no generateSql method exported", t => { +test("bad javascript file - no generateSql method exported", (t) => { const databaseName = "migration-test-javascript-file-errors" const dbConfig = { database: databaseName, @@ -552,12 +552,12 @@ test("bad javascript file - no generateSql method exported", t => { return migrate(dbConfig, "src/__tests__/fixtures/js-no-generate-sql") }) - return t.throwsAsync(promise).then(err => { + return t.throwsAsync(promise).then((err) => { t.regex(err.message, /export a 'generateSql' function/) }) }) -test("bad javascript file - generateSql not returning string literal", t => { +test("bad javascript file - generateSql not returning string literal", (t) => { const databaseName = "migration-test-javascript-no-literal" const dbConfig = { database: databaseName, @@ -571,12 +571,12 @@ test("bad javascript file - generateSql not returning string literal", t => { return migrate(dbConfig, "src/__tests__/fixtures/js-no-string-literal") }) - return t.throwsAsync(promise).then(err => { + return t.throwsAsync(promise).then((err) => { t.regex(err.message, /string literal/) }) }) -test("hash check failure", t => { +test("hash check failure", (t) => { const databaseName = "migration-test-hash-check" const dbConfig = { database: databaseName, @@ -594,13 +594,13 @@ test("hash check failure", t => { migrate(dbConfig, "src/__tests__/fixtures/hash-check/second-run"), ) - return t.throwsAsync(promise).then(err => { + return t.throwsAsync(promise).then((err) => { t.regex(err.message, /Hashes don't match/) t.regex(err.message, /1_migration/, "Should name the problem file") }) }) -test("rollback", t => { +test("rollback", (t) => { const databaseName = "migration-test-rollback" const dbConfig = { database: databaseName, @@ -616,12 +616,12 @@ test("rollback", t => { return t .throwsAsync(promise) - .then(err => { + .then((err) => { t.regex(err.message, /Rolled back/) t.regex(err.message, /trigger-rollback/) }) .then(() => doesTableExist(dbConfig, "should_get_rolled_back")) - .then(exists => { + .then((exists) => { t.false( exists, "The table created in the migration should not have been committed.", @@ -631,7 +631,7 @@ test("rollback", t => { function doesTableExist(dbConfig: pg.ClientConfig, tableName: string) { const client = new pg.Client(dbConfig) - client.on("error", err => console.log("doesTableExist on error", err)) + client.on("error", (err) => console.log("doesTableExist on error", err)) return client .connect() .then(() => @@ -644,14 +644,14 @@ function doesTableExist(dbConfig: pg.ClientConfig, tableName: string) { ); `), ) - .then(result => { + .then((result) => { try { return client .end() .then(() => { return result.rows.length > 0 && result.rows[0].exists }) - .catch(error => { + .catch((error) => { console.log("Async error in 'doesTableExist", error) return result.rows.length > 0 && result.rows[0].exists }) diff --git a/src/__unit__/file-name-parser/index.ts b/src/__unit__/file-name-parser/index.ts index 3b31d76..56cce08 100644 --- a/src/__unit__/file-name-parser/index.ts +++ b/src/__unit__/file-name-parser/index.ts @@ -2,7 +2,7 @@ import test from "ava" import {parseFileName} from "../../file-name-parser" -test("parse name: 1.sql", t => { +test("parse name: 1.sql", (t) => { const parsed = parseFileName("1.sql") t.deepEqual( parsed, @@ -15,7 +15,7 @@ test("parse name: 1.sql", t => { ) }) -test("parse name: 1file.sql", t => { +test("parse name: 1file.sql", (t) => { const parsed = parseFileName("1file.sql") t.deepEqual( parsed, @@ -28,7 +28,7 @@ test("parse name: 1file.sql", t => { ) }) -test("parse name: 1-file.sql", t => { +test("parse name: 1-file.sql", (t) => { const parsed = parseFileName("1-file.sql") t.deepEqual( parsed, @@ -41,7 +41,7 @@ test("parse name: 1-file.sql", t => { ) }) -test("parse name: 1_file.sql", t => { +test("parse name: 1_file.sql", (t) => { const parsed = parseFileName("1_file.sql") t.deepEqual( parsed, @@ -54,7 +54,7 @@ test("parse name: 1_file.sql", t => { ) }) -test("parse name: 1-2_file.sql", t => { +test("parse name: 1-2_file.sql", (t) => { const parsed = parseFileName("1-2_file.sql") t.deepEqual( parsed, @@ -67,7 +67,7 @@ test("parse name: 1-2_file.sql", t => { ) }) -test("parse name: 1_2_file.sql", t => { +test("parse name: 1_2_file.sql", (t) => { const parsed = parseFileName("1_2_file.sql") t.deepEqual( parsed, @@ -80,7 +80,7 @@ test("parse name: 1_2_file.sql", t => { ) }) -test("parse name: 1_file.SQL", t => { +test("parse name: 1_file.SQL", (t) => { const parsed = parseFileName("1_file.SQL") t.deepEqual( parsed, @@ -93,7 +93,7 @@ test("parse name: 1_file.SQL", t => { ) }) -test("parse name: 0001_file.sql", t => { +test("parse name: 0001_file.sql", (t) => { const parsed = parseFileName("0001_file.sql") t.deepEqual( parsed, @@ -106,7 +106,7 @@ test("parse name: 0001_file.sql", t => { ) }) -test("parse name: not_file.sql", t => { +test("parse name: not_file.sql", (t) => { const err = t.throws(() => parseFileName("not_file.sql")) t.regex(err.message, /Invalid file name/) diff --git a/src/__unit__/migration-file/index.ts b/src/__unit__/migration-file/index.ts index 42373db..6190966 100644 --- a/src/__unit__/migration-file/index.ts +++ b/src/__unit__/migration-file/index.ts @@ -1,7 +1,7 @@ import test from "ava" import {load} from "../../migration-file" -test("Hashes of JS files should be the same when the SQL is the same", async t => { +test("Hashes of JS files should be the same when the SQL is the same", async (t) => { const [js1, js2] = await Promise.all([ load(__dirname + "/fixtures/different-js-same-sql-1/1_js.js"), load(__dirname + "/fixtures/different-js-same-sql-2/1_js.js"), @@ -10,7 +10,7 @@ test("Hashes of JS files should be the same when the SQL is the same", async t = t.is(js1.hash, js2.hash) }) -test("Hashes of JS files should be different when the SQL is different", async t => { +test("Hashes of JS files should be different when the SQL is different", async (t) => { const [js1, js2] = await Promise.all([ load(__dirname + "/fixtures/same-js-different-sql-1/1_js.js"), load(__dirname + "/fixtures/same-js-different-sql-2/1_js.js"), diff --git a/src/__unit__/run-migration/index.ts b/src/__unit__/run-migration/index.ts index 86e77c4..64c85d4 100644 --- a/src/__unit__/run-migration/index.ts +++ b/src/__unit__/run-migration/index.ts @@ -15,12 +15,12 @@ let noTransactionSqlFile: string test.before(async () => { await Promise.all([ - readFile(__dirname + "/fixtures/normal.sql", "utf8").then(contents => { + readFile(__dirname + "/fixtures/normal.sql", "utf8").then((contents) => { normalSqlFile = contents }), readFile(__dirname + "/fixtures/no-transaction.sql", "utf8").then( - contents => { + (contents) => { noTransactionSqlFile = contents }, ), @@ -43,7 +43,7 @@ function buildMigration(sql: string): Migration { } const migrationTableName = "migrations" -test("runs a simple migration", t => { +test("runs a simple migration", (t) => { const query = sinon.stub().resolves() const run = runMigration(migrationTableName, {query}) @@ -73,7 +73,7 @@ test("runs a simple migration", t => { }) }) -test("runs a simple js migration", t => { +test("runs a simple js migration", (t) => { const query = sinon.stub().resolves() const run = runMigration(migrationTableName, {query}) @@ -103,14 +103,14 @@ test("runs a simple js migration", t => { }) }) -test("rolls back when there is an error inside a transactiony migration", async t => { +test("rolls back when there is an error inside a transactiony migration", async (t) => { const query = sinon.stub().rejects(new Error("There was a problem")) const run = runMigration(migrationTableName, {query}) const migration = buildMigration(normalSqlFile) t.plan(2) - await run(migration).catch(e => { + await run(migration).catch((e) => { t.is(query.lastCall.args[0], "ROLLBACK", "should perform a rollback") t.true( e.message.indexOf("There was a problem") >= 0, @@ -119,7 +119,7 @@ test("rolls back when there is an error inside a transactiony migration", async }) }) -test("does not run the migration in a transaction when instructed", async t => { +test("does not run the migration in a transaction when instructed", async (t) => { const query = sinon.stub().resolves() const run = runMigration(migrationTableName, {query}) @@ -138,13 +138,13 @@ test("does not run the migration in a transaction when instructed", async t => { }) }) -test("does not roll back when there is an error inside a transactiony migration", async t => { +test("does not roll back when there is an error inside a transactiony migration", async (t) => { const query = sinon.stub().rejects(new Error("There was a problem")) const run = runMigration(migrationTableName, {query}) const migration = buildMigration(noTransactionSqlFile) - await run(migration).catch(e => { + await run(migration).catch((e) => { sinon.assert.neverCalledWith(query, "ROLLBACK") t.true( e.message.indexOf("There was a problem") >= 0, diff --git a/src/create.ts b/src/create.ts index 49cf1bb..29de664 100644 --- a/src/create.ts +++ b/src/create.ts @@ -46,7 +46,7 @@ export async function createDb( host, port, }) - client.on("error", err => { + client.on("error", (err) => { log(`pg client emitted an error: ${err.message}`) }) @@ -59,7 +59,7 @@ function betterCreate(dbName: string, log: Logger) { return async (client: BasicPgClient): Promise => { await client .query(`CREATE DATABASE "${dbName.replace(/\"/g, '""')}"`) - .catch(e => { + .catch((e) => { switch (e.code) { case DUPLICATE_DATABASE: { log(`'${dbName}' database already exists`) diff --git a/src/files-loader.ts b/src/files-loader.ts index 5d2d618..67592f1 100644 --- a/src/files-loader.ts +++ b/src/files-loader.ts @@ -20,7 +20,7 @@ export const load = async ( if (fileNames != null) { const migrationFiles = [ path.join(__dirname, "migrations/0_create-migrations-table.sql"), - ...fileNames.map(fileName => path.resolve(directory, fileName)), + ...fileNames.map((fileName) => path.resolve(directory, fileName)), ].filter(isValidFile) const unorderedMigrations = await Promise.all( diff --git a/src/migrate.ts b/src/migrate.ts index 8ffe73e..414c99f 100644 --- a/src/migrate.ts +++ b/src/migrate.ts @@ -53,7 +53,7 @@ export async function migrate( } const client = new pg.Client(dbConfig) - client.on("error", err => { + client.on("error", (err) => { log(`pg client emitted an error: ${err.message}`) }) diff --git a/src/migration-file.ts b/src/migration-file.ts index cdccff2..8df62ff 100644 --- a/src/migration-file.ts +++ b/src/migration-file.ts @@ -12,10 +12,7 @@ const getFileName = (filePath: string) => path.basename(filePath) const getFileContents = async (filePath: string) => readFile(filePath, "utf8") const hashString = (s: string) => - crypto - .createHash("sha1") - .update(s, "utf8") - .digest("hex") + crypto.createHash("sha1").update(s, "utf8").digest("hex") const getSqlStringLiteral = ( filePath: string, diff --git a/src/with-lock.ts b/src/with-lock.ts index 135e782..4754f77 100644 --- a/src/with-lock.ts +++ b/src/with-lock.ts @@ -16,7 +16,7 @@ export function withAdvisoryLock( if (lockResult.rows[0].pg_try_advisory_lock === true) { acquired = true } else { - await new Promise(res => setTimeout(res, 1000)) + await new Promise((res) => setTimeout(res, 1000)) } } log("... aquired advisory lock")