stepwise-migrations 1.0.17 → 1.0.19

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.
@@ -0,0 +1,34 @@
1
+ # This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
2
+ # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
3
+
4
+ name: Node.js CI
5
+
6
+ on:
7
+ push:
8
+ branches: [main]
9
+ pull_request:
10
+ branches: [main]
11
+ jobs:
12
+ build:
13
+ runs-on: ubuntu-latest
14
+
15
+ strategy:
16
+ matrix:
17
+ node-version: [18.x, 20.x, 22.x, 23.x]
18
+ # See supported Node.js release schedule at https://nodejs.org/en/about/releases/
19
+
20
+ steps:
21
+ - uses: actions/checkout@v4
22
+
23
+ - name: Run docker-compose
24
+ uses: hoverkraft-tech/compose-action@v2.0.1
25
+ with:
26
+ compose-file: "./docker-compose.yml"
27
+
28
+ - name: Use Node.js ${{ matrix.node-version }}
29
+ uses: actions/setup-node@v4
30
+ with:
31
+ node-version: ${{ matrix.node-version }}
32
+ - run: npm ci
33
+ - run: npm run build
34
+ - run: npm test
package/README.md CHANGED
@@ -1,18 +1,48 @@
1
1
  # Stepwise Migrations
2
2
 
3
- [![npm version](https://badge.fury.io/js/stepwise-migrations.svg?icon=si%3Anpm&)](https://badge.fury.io/js/stepwise-migrations)
4
-
5
- A tool for managing Raw SQL migrations in a Postgres database.
3
+ A JavaScript CLI tool for managing Raw SQL migrations in a Postgres database.
6
4
  Loosely based on flyway.
7
5
 
6
+ [![npm version](https://badge.fury.io/js/stepwise-migrations.svg?icon=si%3Anpm&)](https://badge.fury.io/js/stepwise-migrations)
7
+ ![test workflow](https://github.com/github/docs/actions/workflows/test.yml/badge.svg)
8
+
9
+ ## Table of Contents
10
+
11
+ - [Stepwise Migrations](#stepwise-migrations)
12
+ - [Instructions](#instructions)
13
+ - [Usage](#usage)
14
+ - [Examples](#examples)
15
+ - [Migrate](#migrate)
16
+ - [Undo](#undo)
17
+ - [Validate](#validate)
18
+ - [Audit](#audit)
19
+ - [Info](#info)
20
+ - [Get Applied Script](#get-applied-script)
21
+ - [Drop](#drop)
22
+
8
23
  ## Instructions
9
24
 
10
- Up migrations are first sorted in ascending order based on filename.
11
- No subdirectories are read below the migration directory.
25
+ There are three types of migrations:
26
+
27
+ <b>Versioned migrations</b>
28
+
29
+ - The filename must end with `.sql`.
30
+ - These are always applied in ascending order based on filename.
31
+ - Once applied, the file cannot be altered or else an error will be thrown.
32
+
33
+ <b>Repeatable migrations</b>
34
+
35
+ - Are identified by the filename ending with `.repeatable.sql`
36
+ - For things like trigger functions
37
+ - Are always applied after all versioned migrations
38
+ - When altered, the new script is applied on next migration run
39
+
40
+ <b>Undo migrations</b>
12
41
 
13
- Name the "up" migration files as `.sql` and the "down" migration files with the same name but suffixed with `.undo.sql`.
14
- e.g. `v1_users.sql` and `v1_users.undo.sql`.
15
- Down migrations are optional.
42
+ - Run on the "undo" command
43
+ - Can only be run on versioned migrations
44
+ - Are applied in reverse order of the versioned migrations
45
+ - Must have the same filename as the versioned migration but suffixed with `.undo.sql`
16
46
 
17
47
  ## Usage
18
48
 
@@ -40,7 +70,7 @@ Options:
40
70
  --schema <schema> The schema to use for the migrations
41
71
  --path <path> The path to the migrations directory
42
72
  --ssl true/false Whether to use SSL for the connection (default: false)
43
- --napply Number of up migrations to apply (default: all)
73
+ --napply Number of up migrations to apply (default: all)
44
74
  --nundo Number of undo migrations to apply (default: 1)
45
75
  --filename The filename to get the script for (default: last applied migration)
46
76
 
@@ -110,7 +110,7 @@ node_test_1.describe.only("invalid migrations", () => __awaiter(void 0, void 0,
110
110
  recursive: true,
111
111
  });
112
112
  }));
113
- node_test_1.it.only("missing undo migration", () => __awaiter(void 0, void 0, void 0, function* () {
113
+ (0, node_test_1.it)("missing undo migration", () => __awaiter(void 0, void 0, void 0, function* () {
114
114
  (0, utils_1.assertIncludesAll)(yield executeCommand("migrate", paths.invalid), [
115
115
  "All done!",
116
116
  ]);
@@ -126,4 +126,11 @@ node_test_1.describe.only("invalid migrations", () => __awaiter(void 0, void 0,
126
126
  "Versioned migration v1_first.sql has been altered. Cannot migrate in current state.",
127
127
  ]);
128
128
  }));
129
+ node_test_1.it.only("bad creds", () => __awaiter(void 0, void 0, void 0, function* () {
130
+ (0, utils_1.assertIncludesAll)(yield (0, utils_1.execute)(`npm exec stepwise-migrations info -- \\
131
+ --connection=postgresql://postgres:badpassword@127.0.0.1:5432/mydb \\
132
+ --schema=${schema} \\
133
+ --path=${paths.invalid}
134
+ `), ["password authentication failed for user"]);
135
+ }));
129
136
  }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stepwise-migrations",
3
- "version": "1.0.17",
3
+ "version": "1.0.19",
4
4
  "description": "",
5
5
  "main": "./dist/src/index.js",
6
6
  "scripts": {
package/src/utils.ts CHANGED
@@ -14,26 +14,33 @@ Usage: stepwise-migrations [command] [options]
14
14
  Commands:
15
15
  migrate
16
16
  Migrate the database to the latest version
17
- down
17
+ undo
18
18
  Rollback the database to the previous version
19
+ validate
20
+ Validate the migration files and the stepwise_migration_events table
21
+ audit
22
+ Show the audit history for the migrations in the database
19
23
  info
20
24
  Show information about the current state of the migrations in the database
21
25
  drop
22
- Drop the tables, schema and migration history table
26
+ Drop all tables, schema and stepwise_migration_events table
27
+ get-applied-script
28
+ Get the script for the last applied migration
23
29
 
24
30
  Options:
25
31
  --connection <connection> The connection string to use to connect to the database
26
32
  --schema <schema> The schema to use for the migrations
27
33
  --path <path> The path to the migrations directory
28
34
  --ssl true/false Whether to use SSL for the connection (default: false)
29
- --napply Number of up migrations to apply (default: all)
35
+ --napply Number of up migrations to apply (default: all)
30
36
  --nundo Number of undo migrations to apply (default: 1)
37
+ --filename The filename to get the script for (default: last applied migration)
31
38
 
32
39
  Example:
33
40
  npx stepwise-migrations migrate \\
34
41
  --connection=postgresql://postgres:postgres@127.0.0.1:5432/mydatabase \\
35
42
  --schema=myschema \\
36
- --path=./db/migration/
43
+ --path=./test/migrations-template/
37
44
  `;
38
45
 
39
46
  export const validateArgs = (argv: any) => {
@@ -136,7 +136,7 @@ describe.only("invalid migrations", async () => {
136
136
  });
137
137
  });
138
138
 
139
- it.only("missing undo migration", async () => {
139
+ it("missing undo migration", async () => {
140
140
  assertIncludesAll(await executeCommand("migrate", paths.invalid), [
141
141
  "All done!",
142
142
  ]);
@@ -163,4 +163,15 @@ describe.only("invalid migrations", async () => {
163
163
  "Versioned migration v1_first.sql has been altered. Cannot migrate in current state.",
164
164
  ]);
165
165
  });
166
+
167
+ it.only("bad creds", async () => {
168
+ assertIncludesAll(
169
+ await execute(`npm exec stepwise-migrations info -- \\
170
+ --connection=postgresql://postgres:badpassword@127.0.0.1:5432/mydb \\
171
+ --schema=${schema} \\
172
+ --path=${paths.invalid}
173
+ `),
174
+ ["password authentication failed for user"]
175
+ );
176
+ });
166
177
  });
@@ -1 +1,6 @@
1
- ALTER TABLE test ADD COLUMN test_column TEXT;
1
+ create table first (
2
+ id serial primary key,
3
+ name text not null
4
+ );
5
+
6
+ ALTER TABLE first ADD COLUMN age int;