postgres-schema-migrations 6.0.0 → 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/README.md CHANGED
@@ -1,9 +1,7 @@
1
1
  # Postgres schema migrations
2
2
 
3
- ![GitHub Actions](https://github.com/ThomWright/postgres-migrations/actions/workflows/node.js.yml/badge.svg)
4
- [![npm](https://img.shields.io/npm/v/postgres-migrations.svg)](https://www.npmjs.com/package/postgres-migrations)
5
- [![David](https://img.shields.io/david/ThomWright/postgres-migrations.svg)](https://david-dm.org/ThomWright/postgres-migrations)
6
- [![David](https://img.shields.io/david/dev/ThomWright/postgres-migrations.svg)](https://david-dm.org/ThomWright/postgres-migrations)
3
+ ![GitHub Actions](https://github.com/zakpatterson/postgres-schema-migrations/actions/workflows/node.js.yml/badge.svg)
4
+ [![npm](https://img.shields.io/npm/v/postgres-schema-migrations.svg)](https://www.npmjs.com/package/postgres-schema-migrations)
7
5
 
8
6
  This is a fork of Thom Wright's [PostgreSQL migration library](https://github.com/ThomWright/postgres-migrations) which allows for a schema to be specified and for separate migrations to be tracked based on schema. Using Postgres schema namespaces make it easy to reuse database code across projects, so it can be helpful to track migrations for different namespaces.
9
7
 
@@ -29,7 +27,7 @@ There are two ways to use the API.
29
27
  Either, pass a database connection config object:
30
28
 
31
29
  ```typescript
32
- import {migrate} from "postgres-migrations"
30
+ import {migrate} from "postgres-schema-migrations"
33
31
 
34
32
  async function() {
35
33
  const dbConfig = {
@@ -55,7 +53,7 @@ async function() {
55
53
  Or, pass a `pg` client:
56
54
 
57
55
  ```typescript
58
- import {migrate} from "postgres-migrations"
56
+ import {migrate} from "postgres-schema-migrations"
59
57
 
60
58
  async function() {
61
59
  const dbConfig = {
@@ -81,7 +79,7 @@ async function() {
81
79
 
82
80
  To track migrations within a given schema, just pass an additional `{schema: "your_schema_name"}` parameter to `migrate`, as in:
83
81
 
84
- ```
82
+ ```typescript
85
83
  try {
86
84
  await migrate({client}, "path/to/schema/migration/files", {schema: "schema_name"})
87
85
  } finally {
@@ -0,0 +1,71 @@
1
+ {
2
+ "name": "postgres-schema-migrations",
3
+ "version": "6.0.3",
4
+ "description": "Stack Overflow style database migrations for PostgreSQL",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "bin": {
8
+ "pg-validate-migrations": "./dist/bin/validate.js"
9
+ },
10
+ "authors": ["Thom Wright", "Zak Patterson"],
11
+ "keywords": [
12
+ "postgres",
13
+ "postgresql",
14
+ "migration",
15
+ "migrations",
16
+ "sql",
17
+ "database",
18
+ "db"
19
+ ],
20
+ "homepage": "https://github.com/zakpatterson/postgres-schema-migrations#readme",
21
+ "license": "MIT",
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "git@github.com:zakpatterson/postgres-schema-migrations.git"
25
+ },
26
+ "bugs": {
27
+ "url": "https://github.com/zakpatterson/postgres-schema-migrations/issues"
28
+ },
29
+ "engines": {
30
+ "node": ">10.17.0"
31
+ },
32
+ "scripts": {
33
+ "checkPushed": "[ \"$(git rev-list --count @{upstream}..HEAD)\" -eq 0 ] || (echo You have unpushed commits && exit 1)",
34
+ "prepublishOnly": "npm run checkPushed && npm test && npm run build",
35
+ "check-formatting": "./node_modules/.bin/prettier '**/*.ts' --list-different",
36
+ "fix-formatting": "./node_modules/.bin/prettier '**/*.ts' --write",
37
+ "lint": "npm run tslint && npm run check-formatting",
38
+ "tslint": "tslint 'src/**/*.ts' --type-check --project tsconfig.json --format verbose",
39
+ "test-integration": "ava --config ava.config.integration.cjs",
40
+ "test-unit": "ava --config ava.config.unit.cjs",
41
+ "test": "npm run test-unit && npm run lint && npm run test-integration",
42
+ "preversion": "npm test",
43
+ "build": "rm -rf ./dist && rsync -a --exclude='*.ts' --exclude='__tests__' --exclude='__unit__' --prune-empty-dirs src/ dist/ && tsc --project tsconfig-build.json && cp ./package.json ./dist/"
44
+ },
45
+ "husky": {
46
+ "hooks": {
47
+ "commit-msg": "node ./node_modules/fit-commit-js/lib/hook.js .git/COMMIT_EDITMSG",
48
+ "pre-commit": "npm run lint",
49
+ "pre-push": "npm test"
50
+ }
51
+ },
52
+ "dependencies": {
53
+ "pg": "^8.6.0",
54
+ "sql-template-strings": "^2.2.2"
55
+ },
56
+ "devDependencies": {
57
+ "@types/node": "^10.17.60",
58
+ "@types/pg": "^8.6.0",
59
+ "@types/sinon": "^9.0.11",
60
+ "ava": "^3.15.0",
61
+ "fit-commit-js": "^0.3.2",
62
+ "husky": "^3.1.0",
63
+ "prettier": "^2.3.1",
64
+ "sinon": "^9.2.4",
65
+ "ts-node": "^10.0.0",
66
+ "tslint": "^6.1.3",
67
+ "tslint-config-prettier": "^1.18.0",
68
+ "typescript": "^4.3.4",
69
+ "typescript-tslint-plugin": "^1.0.1"
70
+ }
71
+ }
@@ -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 ? () => client.query("START TRANSACTION") : noop;
20
- const end = inTransaction ? () => client.query("COMMIT") : noop;
21
- const cleanup = inTransaction ? () => client.query("ROLLBACK") : noop;
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
- await end();
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.0",
3
+ "version": "6.0.3",
4
4
  "description": "Stack Overflow style database migrations for PostgreSQL",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -40,7 +40,7 @@
40
40
  "test-unit": "ava --config ava.config.unit.cjs",
41
41
  "test": "npm run test-unit && npm run lint && npm run test-integration",
42
42
  "preversion": "npm test",
43
- "build": "rm -rf ./dist && rsync -a --exclude='*.ts' --exclude='__tests__' --exclude='__unit__' --prune-empty-dirs src/ dist/ && tsc --project tsconfig-build.json"
43
+ "build": "rm -rf ./dist && rsync -a --exclude='*.ts' --exclude='__tests__' --exclude='__unit__' --prune-empty-dirs src/ dist/ && tsc --project tsconfig-build.json && cp ./package.json ./dist/"
44
44
  },
45
45
  "husky": {
46
46
  "hooks": {