stepwise-migrations 1.0.9 → 1.0.10
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 +157 -11
- package/package.json +1 -1
package/README.md
CHANGED
@@ -16,7 +16,7 @@ No subdirectories are read below the migration directory.
|
|
16
16
|
|
17
17
|
## Usage
|
18
18
|
|
19
|
-
```
|
19
|
+
```text
|
20
20
|
Usage: stepwise-migrations [command] [options]
|
21
21
|
|
22
22
|
Commands:
|
@@ -64,6 +64,31 @@ npx stepwise-migrations migrate \
|
|
64
64
|
--path=./db/migration/
|
65
65
|
```
|
66
66
|
|
67
|
+
<details>
|
68
|
+
|
69
|
+
<summary>Example output</summary>
|
70
|
+
|
71
|
+
```text
|
72
|
+
Creating schema myschema... done!
|
73
|
+
Creating migration history table... done!
|
74
|
+
Applying migration v1_connect_session_table.sql... done!
|
75
|
+
Applying migration v2_auth.sql... done!
|
76
|
+
All done! Applied 2 migrations
|
77
|
+
Migration history:
|
78
|
+
┌─────────┬────┬────────────────────────────────┬────────────┬──────────────────────────────┐
|
79
|
+
│ (index) │ id │ name │ applied_by │ applied_at │
|
80
|
+
├─────────┼────┼────────────────────────────────┼────────────┼──────────────────────────────┤
|
81
|
+
│ 0 │ 1 │ 'v1_connect_session_table.sql' │ 'postgres' │ '2024-11-24 05:40:41.211617' │
|
82
|
+
│ 1 │ 2 │ 'v2_auth.sql' │ 'postgres' │ '2024-11-24 05:40:41.214732' │
|
83
|
+
└─────────┴────┴────────────────────────────────┴────────────┴──────────────────────────────┘
|
84
|
+
Unapplied migrations:
|
85
|
+
┌─────────┐
|
86
|
+
│ (index) │
|
87
|
+
├─────────┤
|
88
|
+
```
|
89
|
+
|
90
|
+
</details>
|
91
|
+
|
67
92
|
### Down
|
68
93
|
|
69
94
|
Runs a single down migration for the last applied migration.
|
@@ -78,6 +103,29 @@ npx stepwise-migrations down \
|
|
78
103
|
--path=./db/migration/
|
79
104
|
```
|
80
105
|
|
106
|
+
<details>
|
107
|
+
|
108
|
+
<summary>Example output</summary>
|
109
|
+
|
110
|
+
```text
|
111
|
+
Applying down migration v2_auth.down.sql... done!
|
112
|
+
All done! Applied 1 down migration
|
113
|
+
Migration history:
|
114
|
+
┌─────────┬────┬────────────────────────────────┬────────────┬──────────────────────────────┐
|
115
|
+
│ (index) │ id │ name │ applied_by │ applied_at │
|
116
|
+
├─────────┼────┼────────────────────────────────┼────────────┼──────────────────────────────┤
|
117
|
+
│ 0 │ 1 │ 'v1_connect_session_table.sql' │ 'postgres' │ '2024-11-24 05:40:41.211617' │
|
118
|
+
└─────────┴────┴────────────────────────────────┴────────────┴──────────────────────────────┘
|
119
|
+
Unapplied migrations:
|
120
|
+
┌─────────┬───────────────┐
|
121
|
+
│ (index) │ filename │
|
122
|
+
├─────────┼───────────────┤
|
123
|
+
│ 0 │ 'v2_auth.sql' │
|
124
|
+
└─────────┴───────────────┘
|
125
|
+
```
|
126
|
+
|
127
|
+
</details>
|
128
|
+
|
81
129
|
### Validate
|
82
130
|
|
83
131
|
Validates the migration files and the migration history table.
|
@@ -89,6 +137,46 @@ npx stepwise-migrations validate \
|
|
89
137
|
--path=./db/migration/
|
90
138
|
```
|
91
139
|
|
140
|
+
<details>
|
141
|
+
|
142
|
+
<summary>Example output - validation passed</summary>
|
143
|
+
|
144
|
+
```text
|
145
|
+
Validation passed
|
146
|
+
Migration history:
|
147
|
+
┌─────────┬────┬────────────────────────────────┬────────────┬──────────────────────────────┐
|
148
|
+
│ (index) │ id │ name │ applied_by │ applied_at │
|
149
|
+
├─────────┼────┼────────────────────────────────┼────────────┼──────────────────────────────┤
|
150
|
+
│ 0 │ 1 │ 'v1_connect_session_table.sql' │ 'postgres' │ '2024-11-24 05:40:41.211617' │
|
151
|
+
└─────────┴────┴────────────────────────────────┴────────────┴──────────────────────────────┘
|
152
|
+
Unapplied migrations:
|
153
|
+
┌─────────┬───────────────┐
|
154
|
+
│ (index) │ filename │
|
155
|
+
├─────────┼───────────────┤
|
156
|
+
│ 0 │ 'v2_auth.sql' │
|
157
|
+
└─────────┴───────────────┘
|
158
|
+
```
|
159
|
+
|
160
|
+
</details>
|
161
|
+
|
162
|
+
<details>
|
163
|
+
|
164
|
+
<summary>Example output - script changed error</summary>
|
165
|
+
|
166
|
+
```sql
|
167
|
+
Error: migration v1_connect_session_table.sql has been modified, aborting.
|
168
|
+
"expire" timestamp(6) NOT NULL
|
169
|
+
)
|
170
|
+
WITH (OIDS=FALSE);
|
171
|
+
-ALTER TABLE "session" ADD CONSTRAINT "session_pkey" PRIMARY KEY ("sid") NOT DEFERRABLE INITIALLY IMMEDIATE;
|
172
|
+
|
173
|
+
+ALTER TABLE "session" ADD CONSTRAINT "session_pkey" PRIMARY KEY ("sid") NOT DEFERRABLE INITIALLY IMMEDIATE;
|
174
|
+
+
|
175
|
+
+ALTER TABLE "session" ADD INDEX "session_sid" ON "session" (sid);
|
176
|
+
```
|
177
|
+
|
178
|
+
</details>
|
179
|
+
|
92
180
|
### Audit
|
93
181
|
|
94
182
|
Shows the audit history for the migrations in the database.
|
@@ -100,6 +188,23 @@ npx stepwise-migrations audit \
|
|
100
188
|
--path=./db/migration/
|
101
189
|
```
|
102
190
|
|
191
|
+
<details>
|
192
|
+
|
193
|
+
<summary>Example output</summary>
|
194
|
+
|
195
|
+
```text
|
196
|
+
Audit history:
|
197
|
+
┌─────────┬────┬────────┬────────────────────────────────┬────────────┬──────────────────────────────┐
|
198
|
+
│ (index) │ id │ type │ name │ applied_by │ applied_at │
|
199
|
+
├─────────┼────┼────────┼────────────────────────────────┼────────────┼──────────────────────────────┤
|
200
|
+
│ 0 │ 1 │ 'up' │ 'v1_connect_session_table.sql' │ 'postgres' │ '2024-11-24 05:40:41.211617' │
|
201
|
+
│ 1 │ 2 │ 'up' │ 'v2_auth.sql' │ 'postgres' │ '2024-11-24 05:40:41.214732' │
|
202
|
+
│ 2 │ 3 │ 'down' │ 'v2_auth.down.sql' │ 'postgres' │ '2024-11-24 05:41:34.541462' │
|
203
|
+
└─────────┴────┴────────┴────────────────────────────────┴────────────┴──────────────────────────────┘
|
204
|
+
```
|
205
|
+
|
206
|
+
</details>
|
207
|
+
|
103
208
|
### Info
|
104
209
|
|
105
210
|
Shows the current state of the migrations in the database.
|
@@ -113,18 +218,21 @@ npx stepwise-migrations info \
|
|
113
218
|
--path=./db/migration/
|
114
219
|
```
|
115
220
|
|
116
|
-
|
117
|
-
|
118
|
-
Drops the tables, schema and migration history table.
|
221
|
+
<details>
|
119
222
|
|
120
|
-
|
223
|
+
<summary>Example output</summary>
|
121
224
|
|
122
|
-
```
|
123
|
-
|
124
|
-
|
125
|
-
|
225
|
+
```text
|
226
|
+
Migration history:
|
227
|
+
┌─────────┬────┬────────────────────────────────┬────────────┬──────────────────────────────┐
|
228
|
+
│ (index) │ id │ name │ applied_by │ applied_at │
|
229
|
+
├─────────┼────┼────────────────────────────────┼────────────┼──────────────────────────────┤
|
230
|
+
│ 0 │ 1 │ 'v1_connect_session_table.sql' │ 'postgres' │ '2024-11-24 05:40:41.211617' │
|
231
|
+
└─────────┴────┴────────────────────────────────┴────────────┴──────────────────────────────┘
|
126
232
|
```
|
127
233
|
|
234
|
+
</details>
|
235
|
+
|
128
236
|
### Get Script
|
129
237
|
|
130
238
|
Gets the script for the last applied migration.
|
@@ -133,8 +241,46 @@ Can get the script for a specific migration if the `--filename` option is provid
|
|
133
241
|
Command:
|
134
242
|
|
135
243
|
```bash
|
136
|
-
npx stepwise-migrations get-script \
|
137
|
-
--
|
244
|
+
npx stepwise-migrations get-script --filename v2_auth.sql \
|
245
|
+
--connection=postgresql://postgres:postgres@127.0.0.1:5432/colliedb \
|
246
|
+
--schema=collie \
|
247
|
+
--path=./db/migration/
|
248
|
+
```
|
249
|
+
|
250
|
+
<details>
|
251
|
+
|
252
|
+
<summary>Example output</summary>
|
253
|
+
|
254
|
+
```sql
|
255
|
+
CREATE TABLE "users" (
|
256
|
+
id bigserial primary key,
|
257
|
+
email text unique not null,
|
258
|
+
first_name text not null,
|
259
|
+
last_name text not null,
|
260
|
+
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
261
|
+
);
|
262
|
+
```
|
263
|
+
|
264
|
+
</details>
|
265
|
+
|
266
|
+
### Drop
|
267
|
+
|
268
|
+
Drops the tables, schema and migration history table.
|
269
|
+
|
270
|
+
Command:
|
271
|
+
|
272
|
+
```bash
|
273
|
+
npx stepwise-migrations drop \
|
138
274
|
--connection=postgresql://postgres:postgres@127.0.0.1:5432/mydb \
|
139
275
|
--schema=myschema
|
140
276
|
```
|
277
|
+
|
278
|
+
<details>
|
279
|
+
|
280
|
+
<summary>Example output</summary>
|
281
|
+
|
282
|
+
```text
|
283
|
+
Dropping the tables, schema and migration history table... done!
|
284
|
+
```
|
285
|
+
|
286
|
+
</details>
|