drizzle-kit 0.17.0-fac8395 → 0.17.0
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/index.js +15 -5
- package/package.json +2 -2
- package/readme.md +88 -14
package/index.js
CHANGED
|
@@ -17553,6 +17553,7 @@ var init_upFolders = __esm({
|
|
|
17553
17553
|
date.setUTCHours(Number(it.substring(8, 10)));
|
|
17554
17554
|
date.setUTCMinutes(Number(it.substring(10, 12)));
|
|
17555
17555
|
date.setUTCSeconds(Number(it.substring(12, 14)));
|
|
17556
|
+
date.setUTCMilliseconds(0);
|
|
17556
17557
|
const path2 = (0, import_path.join)(out, it);
|
|
17557
17558
|
const pathJson = (0, import_path.join)(out, it, "snapshot.json");
|
|
17558
17559
|
const pathSQL = (0, import_path.join)(out, it, "migration.sql");
|
|
@@ -27180,7 +27181,7 @@ var init_migrate = __esm({
|
|
|
27180
27181
|
result.deleted.push(...leftMissing);
|
|
27181
27182
|
return result;
|
|
27182
27183
|
};
|
|
27183
|
-
writeResult = (cur, sqlStatements, journal, _meta, outFolder, breakpoints) => {
|
|
27184
|
+
writeResult = (cur, sqlStatements, journal, _meta, outFolder, breakpoints, isIntrospect = false) => {
|
|
27184
27185
|
console.log(schema(cur));
|
|
27185
27186
|
if (sqlStatements.length === 0) {
|
|
27186
27187
|
console.log("No schema changes, nothing to migrate \u{1F634}");
|
|
@@ -27198,7 +27199,14 @@ var init_migrate = __esm({
|
|
|
27198
27199
|
JSON.stringify(toSave, null, 2)
|
|
27199
27200
|
);
|
|
27200
27201
|
const sqlDelimiter = breakpoints ? "--> statement-breakpoint\n" : "\n";
|
|
27201
|
-
|
|
27202
|
+
let sql = sqlStatements.join(sqlDelimiter);
|
|
27203
|
+
if (isIntrospect) {
|
|
27204
|
+
sql = `-- Current sql file was generated after introspecting the database
|
|
27205
|
+
-- If you want to run this migration please uncomment this code before executing migraitons
|
|
27206
|
+
/*
|
|
27207
|
+
${sql}
|
|
27208
|
+
*/`;
|
|
27209
|
+
}
|
|
27202
27210
|
journal.entries.push({
|
|
27203
27211
|
idx,
|
|
27204
27212
|
version: cur.version,
|
|
@@ -49277,7 +49285,7 @@ var package_default = {
|
|
|
49277
49285
|
"migrate:old:mysql": "drizzle-kit generate:mysql --out ./dev/migrations-mysql --schema ./dev/migrations-mysql/schema.ts",
|
|
49278
49286
|
"start:pg": "node -r esbuild-register ./src/cli/index.ts generate:pg --out ./dev/migrations-pg --schema ./dev/migrations-pg/schema.ts",
|
|
49279
49287
|
"start:sqlite": "node -r esbuild-register ./src/cli/index.ts generate:sqlite --out ./dev/migrations-sqlite --schema ./dev/migrations-sqlite/schema.ts",
|
|
49280
|
-
"start:mysql": "node -r esbuild-register ./src/cli/index.ts generate:mysql --out ./dev/
|
|
49288
|
+
"start:mysql": "node -r esbuild-register ./src/cli/index.ts generate:mysql --out ./dev/migrations-mysql --schema ./dev/migrations-mysql/schema.ts",
|
|
49281
49289
|
"check:pg": "node -r esbuild-register ./src/cli/index.ts check --out ./dev/migrations --dialect pg",
|
|
49282
49290
|
"introspect:mysql": "node -r esbuild-register ./src/cli/index.ts introspect:mysql --out ./dev/introspect-mysql --connectionString",
|
|
49283
49291
|
"introspect:pg": "node -r esbuild-register ./src/cli/index.ts introspect:pg --out ./dev/introspect-pg --connectionString=postgresql://postgres@localhost:5432/introspect",
|
|
@@ -49648,7 +49656,8 @@ var introspectPgCommand = new Command("introspect:pg").option("--out <out>", `Mi
|
|
|
49648
49656
|
journal,
|
|
49649
49657
|
_meta,
|
|
49650
49658
|
res.data.out,
|
|
49651
|
-
res.data.breakpoints
|
|
49659
|
+
res.data.breakpoints,
|
|
49660
|
+
true
|
|
49652
49661
|
);
|
|
49653
49662
|
} else {
|
|
49654
49663
|
(0, import_hanji6.render)(
|
|
@@ -49699,7 +49708,8 @@ var introspectMySqlCommand = new Command("introspect:mysql").option("--out <out>
|
|
|
49699
49708
|
journal,
|
|
49700
49709
|
_meta,
|
|
49701
49710
|
res.data.out,
|
|
49702
|
-
res.data.breakpoints
|
|
49711
|
+
res.data.breakpoints,
|
|
49712
|
+
true
|
|
49703
49713
|
);
|
|
49704
49714
|
} else {
|
|
49705
49715
|
(0, import_hanji6.render)(
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "drizzle-kit",
|
|
3
|
-
"version": "0.17.0
|
|
3
|
+
"version": "0.17.0",
|
|
4
4
|
"repository": "https://github.com/drizzle-team/drizzle-kit-mirror",
|
|
5
5
|
"author": "Drizzle Team",
|
|
6
6
|
"license": "MIT",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"migrate:old:mysql": "drizzle-kit generate:mysql --out ./dev/migrations-mysql --schema ./dev/migrations-mysql/schema.ts",
|
|
13
13
|
"start:pg": "node -r esbuild-register ./src/cli/index.ts generate:pg --out ./dev/migrations-pg --schema ./dev/migrations-pg/schema.ts",
|
|
14
14
|
"start:sqlite": "node -r esbuild-register ./src/cli/index.ts generate:sqlite --out ./dev/migrations-sqlite --schema ./dev/migrations-sqlite/schema.ts",
|
|
15
|
-
"start:mysql": "node -r esbuild-register ./src/cli/index.ts generate:mysql --out ./dev/
|
|
15
|
+
"start:mysql": "node -r esbuild-register ./src/cli/index.ts generate:mysql --out ./dev/migrations-mysql --schema ./dev/migrations-mysql/schema.ts",
|
|
16
16
|
"check:pg": "node -r esbuild-register ./src/cli/index.ts check --out ./dev/migrations --dialect pg",
|
|
17
17
|
"introspect:mysql": "node -r esbuild-register ./src/cli/index.ts introspect:mysql --out ./dev/introspect-mysql --connectionString",
|
|
18
18
|
"introspect:pg": "node -r esbuild-register ./src/cli/index.ts introspect:pg --out ./dev/introspect-pg --connectionString=postgresql://postgres@localhost:5432/introspect",
|
package/readme.md
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
## Drizzle Kit
|
|
2
|
+
|
|
2
3
|
DrizzleKit - is a CLI migrator tool for DrizzleORM. It is probably one and only tool that lets you completely automatically generate SQL migrations and covers ~95% of the common cases like delitions and renames by prompting user input.\
|
|
3
|
-
https://github.com/drizzle-team/drizzle-kit-mirror - is a mirror repository for issues.
|
|
4
|
+
<https://github.com/drizzle-team/drizzle-kit-mirror> - is a mirror repository for issues.
|
|
4
5
|
|
|
5
6
|
### How it works
|
|
7
|
+
|
|
6
8
|
`drizzle-kit` will traverse `schema folder` or `schema file`, generate schema snapshot and compare it to the previous version(if there's one).\
|
|
7
9
|
Based on the difference it will generate all needed SQL migrations and if there're any `automatically unresolvable` cases like `renames` it will prompt user for input.
|
|
8
10
|
|
|
9
11
|
For schema file:
|
|
12
|
+
|
|
10
13
|
```typescript
|
|
11
14
|
// ./src/db/schema.ts
|
|
12
15
|
|
|
@@ -26,17 +29,19 @@ export const authOtp = pgTable("auth_otp", {
|
|
|
26
29
|
userId: integer("user_id").references(() => users.id),
|
|
27
30
|
});
|
|
28
31
|
```
|
|
32
|
+
|
|
29
33
|
It will generate:
|
|
34
|
+
|
|
30
35
|
```SQL
|
|
31
36
|
CREATE TABLE IF NOT EXISTS auth_otp (
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
37
|
+
"id" SERIAL PRIMARY KEY,
|
|
38
|
+
"phone" character varying(256),
|
|
39
|
+
"user_id" INT
|
|
35
40
|
);
|
|
36
41
|
|
|
37
42
|
CREATE TABLE IF NOT EXISTS users (
|
|
38
|
-
|
|
39
|
-
|
|
43
|
+
"id" SERIAL PRIMARY KEY,
|
|
44
|
+
"full_name" character varying(256)
|
|
40
45
|
);
|
|
41
46
|
|
|
42
47
|
DO $$ BEGIN
|
|
@@ -49,26 +54,69 @@ CREATE INDEX IF NOT EXISTS users_full_name_index ON users (full_name);
|
|
|
49
54
|
```
|
|
50
55
|
|
|
51
56
|
### Installation & configuration
|
|
57
|
+
|
|
52
58
|
```shell
|
|
53
|
-
|
|
59
|
+
npm install -D drizzle-kit
|
|
54
60
|
```
|
|
55
61
|
|
|
56
62
|
Running with CLI options
|
|
63
|
+
|
|
57
64
|
```shell
|
|
58
|
-
|
|
65
|
+
npm exec drizzle-kit generate --out migrations-folder --dialect pg --schema src/db/schema.ts
|
|
59
66
|
```
|
|
60
67
|
|
|
61
68
|
Or put your file to `drizzle.config.json` configuration file:
|
|
69
|
+
|
|
62
70
|
```json
|
|
63
71
|
{
|
|
64
72
|
"out": "./migrations-folder",
|
|
65
73
|
"schema": "./src/db"
|
|
66
74
|
}
|
|
67
75
|
```
|
|
76
|
+
|
|
68
77
|
---
|
|
78
|
+
|
|
79
|
+
## Upgrading to 0.17.0
|
|
80
|
+
|
|
81
|
+
Before running any new migrations `drizzle-kit` will ask you to upgrade in a first place
|
|
82
|
+
|
|
83
|
+
Migration file structure < 0.17.0
|
|
84
|
+
|
|
85
|
+
```plaintext
|
|
86
|
+
📦 <project root>
|
|
87
|
+
└ 📂 migrations
|
|
88
|
+
└ 📂 20221207174503
|
|
89
|
+
├ 📜 migration.sql
|
|
90
|
+
├ 📜 snapshot.json
|
|
91
|
+
└ 📂 20230101104503
|
|
92
|
+
├ 📜 migration.sql
|
|
93
|
+
├ 📜 snapshot.json
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Migration file structure >= 0.17.0
|
|
97
|
+
|
|
98
|
+
```plaintext
|
|
99
|
+
📦 <project root>
|
|
100
|
+
└ 📂 migrations
|
|
101
|
+
└ 📂 meta
|
|
102
|
+
├ 📜 _journal.json
|
|
103
|
+
├ 📜 0000_snapshot.json
|
|
104
|
+
├ 📜 0001_snapshot.json
|
|
105
|
+
└ 📜 0000_icy_stranger.sql
|
|
106
|
+
└ 📜 0001_strange_avengers.sql
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
To easily migrate from previous folder structure to new you need to run `up` command in drizzle kit. It's a great helper to upgrade your migrations to new format on each drizzle kit major update
|
|
110
|
+
|
|
111
|
+

|
|
112
|
+
---
|
|
113
|
+
|
|
69
114
|
## List of commands
|
|
70
115
|
|
|
71
116
|
### Generate SQL migrations based on current .ts schema\
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
72
120
|
**`$ drizzle-kit generate:pg`** \
|
|
73
121
|
**`$ drizzle-kit generate:mysql`** \
|
|
74
122
|
**`$ drizzle-kit generate:sqlite`** \
|
|
@@ -76,6 +124,7 @@ Or put your file to `drizzle.config.json` configuration file:
|
|
|
76
124
|
`--config` [optional defalut=drizzle.config.json] config file path\
|
|
77
125
|
`--schema` path to typescript schema file or folder with multiple schema files\
|
|
78
126
|
`--out` [optional default=drizzle/] migrations folder
|
|
127
|
+
|
|
79
128
|
```shell
|
|
80
129
|
$ drizzle-kit generate:pg
|
|
81
130
|
## runs generate command with drizzle.config.json
|
|
@@ -91,40 +140,65 @@ $ drizzle-kit generate:pg --schema=./src/schema.ts --out=./migrations/
|
|
|
91
140
|
```
|
|
92
141
|
|
|
93
142
|
### Introspect existing database and generate typescript schema
|
|
94
|
-
|
|
143
|
+
|
|
144
|
+
---
|
|
145
|
+
|
|
146
|
+
**`$ drizzle-kit introspect:pg`** \
|
|
147
|
+
**`$ drizzle-kit introspect:mysql`**
|
|
148
|
+
|
|
95
149
|
```shell
|
|
96
150
|
drizzle-kit introspect:pg --out=migrations/ --connectionString=postgresql://user:pass@host:port/db_name
|
|
97
151
|
|
|
98
152
|
drizzle-kit introspect:pg --out=migrations/ --host=0.0.0.0 --port=5432 --user=postgres --password=pass --database=db_name --ssl
|
|
99
153
|
```
|
|
100
154
|
|
|
155
|
+

|
|
156
|
+
|
|
101
157
|
### Update stale snapshots
|
|
158
|
+
|
|
159
|
+
---
|
|
160
|
+
|
|
102
161
|
**`$ drizzle-kit up:pg`** \
|
|
103
162
|
**`$ drizzle-kit up:mysql`**\
|
|
104
163
|
**`$ drizzle-kit up:sqlite`**
|
|
105
164
|
|
|
106
165
|
`--out` [optional] migrations folder\
|
|
107
166
|
`--config` [optional defalut=drizzle.config.json] config file path
|
|
167
|
+
|
|
108
168
|
```shell
|
|
109
169
|
## migrations folder is taken from drizzle.config.json
|
|
110
|
-
drizzle-kit up:
|
|
170
|
+
drizzle-kit up:mysql
|
|
111
171
|
|
|
112
|
-
drizzle-kit up:
|
|
172
|
+
drizzle-kit up:mysql --out=migrations/
|
|
113
173
|
```
|
|
114
174
|
|
|
175
|
+

|
|
176
|
+
|
|
177
|
+
### Drop migration
|
|
178
|
+
|
|
179
|
+
---
|
|
180
|
+
|
|
181
|
+
**`$ drizzle-kit drop`** \
|
|
182
|
+
|
|
183
|
+
`--out` [optional] migrations folder\
|
|
184
|
+
`--config` [optional defalut=drizzle.config.json] config file path
|
|
185
|
+
|
|
186
|
+

|
|
187
|
+
|
|
115
188
|
### Migrations collisions check
|
|
189
|
+
|
|
190
|
+
---
|
|
191
|
+
|
|
116
192
|
**`$ drizzle-kit check:pg`**\
|
|
117
193
|
**`$ drizzle-kit check:mysql`**\
|
|
118
194
|
**`$ drizzle-kit check:sqlite`**
|
|
119
195
|
|
|
120
196
|
`--out` [optional] migration folder\
|
|
121
197
|
`--config` [optional defalut=drizzle.config.json] config file path
|
|
198
|
+
|
|
122
199
|
```shell
|
|
123
200
|
## migrations folder is taken from drizzle.config.json
|
|
124
201
|
drizzle-kit check:pg
|
|
125
202
|
|
|
126
203
|
drizzle-kit check:pg --out=migrations/
|
|
127
204
|
```
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|