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.
- package/.github/workflows/test.yml +1 -2
- package/README.md +7 -14
- package/dist/test/index.test.js +8 -1
- package/package.json +1 -1
- package/src/index.ts +0 -1
- package/src/utils.ts +11 -4
- package/test/index.test.ts +12 -1
- package/test/migrations-invalid/v1_first.sql +6 -1
@@ -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
|
-
-
|
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
|
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:
|
package/dist/test/index.test.js
CHANGED
@@ -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
|
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
package/src/index.ts
CHANGED
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
|
-
|
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
|
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
|
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=./
|
43
|
+
--path=./test/migrations-template/
|
37
44
|
`;
|
38
45
|
|
39
46
|
export const validateArgs = (argv: any) => {
|
package/test/index.test.ts
CHANGED
@@ -136,7 +136,7 @@ describe.only("invalid migrations", async () => {
|
|
136
136
|
});
|
137
137
|
});
|
138
138
|
|
139
|
-
it
|
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
|
});
|