stepwise-migrations 1.0.18 → 1.0.20

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.
@@ -14,7 +14,7 @@ jobs:
14
14
 
15
15
  strategy:
16
16
  matrix:
17
- node-version: [18.x, 20.x, 22.x]
17
+ node-version: [18.x, 20.x, 22.x, 23.x]
18
18
  # See supported Node.js release schedule at https://nodejs.org/en/about/releases/
19
19
 
20
20
  steps:
@@ -29,7 +29,6 @@ jobs:
29
29
  uses: actions/setup-node@v4
30
30
  with:
31
31
  node-version: ${{ matrix.node-version }}
32
- cache: "npm"
33
32
  - run: npm ci
34
33
  - run: npm run build
35
34
  - run: npm test
package/README.md CHANGED
@@ -24,25 +24,25 @@ Loosely based on flyway.
24
24
 
25
25
  There are three types of migrations:
26
26
 
27
- <b>Versioned migrations</b>
27
+ <b>1. Versioned migrations</b>
28
28
 
29
29
  - The filename must end with `.sql`.
30
30
  - These are always applied in ascending order based on filename.
31
31
  - Once applied, the file cannot be altered or else an error will be thrown.
32
32
 
33
- <b>Repeatable migrations</b>
33
+ <b>2. Repeatable migrations</b>
34
34
 
35
35
  - Are identified by the filename ending with `.repeatable.sql`
36
36
  - For things like trigger functions
37
37
  - Are always applied after all versioned migrations
38
38
  - When altered, the new script is applied on next migration run
39
39
 
40
- <b>Undo migrations</b>
40
+ <b>3. Undo migrations</b>
41
41
 
42
- - Run on the "undo" command
43
- - Can only be run on versioned migrations
44
- - Are applied in reverse order of the versioned migrations
42
+ - Are completely optional
45
43
  - Must have the same filename as the versioned migration but suffixed with `.undo.sql`
44
+ - Are applied in reverse order of the versioned migrations
45
+ - Can only be for undoing versioned migrations, not repeatable migrations. For repeatable migrations, simply delete the trigger function in the repeatable migration file and migrate again.
46
46
 
47
47
  ## Usage
48
48
 
@@ -70,7 +70,7 @@ Options:
70
70
  --schema <schema> The schema to use for the migrations
71
71
  --path <path> The path to the migrations directory
72
72
  --ssl true/false Whether to use SSL for the connection (default: false)
73
- --napply Number of up migrations to apply (default: all)
73
+ --napply Number of up migrations to apply (default: all)
74
74
  --nundo Number of undo migrations to apply (default: 1)
75
75
  --filename The filename to get the script for (default: last applied migration)
76
76
 
@@ -150,13 +150,6 @@ npx stepwise-migrations undo \
150
150
  <summary>Example output</summary>
151
151
 
152
152
  ```text
153
- [
154
- {
155
- type: 'undo',
156
- filename: 'v3_third.undo.sql',
157
- script: 'drop table third;'
158
- }
159
- ]
160
153
  Applying undo migration v3_third.undo.sql... done!
161
154
  All done! Performed 1 undo migration
162
155
  All applied versioned migrations:
@@ -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.18",
3
+ "version": "1.0.20",
4
4
  "description": "",
5
5
  "main": "./dist/src/index.js",
6
6
  "scripts": {
package/src/index.ts CHANGED
@@ -147,7 +147,6 @@ const main = async () => {
147
147
  process.exit(1);
148
148
  }
149
149
 
150
- console.log(undosToApply);
151
150
  for (const { filename, script } of undosToApply) {
152
151
  await applyUndoMigration(client, schema, filename, script);
153
152
  }
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;