drizzle-kit 0.17.0-5763371 → 0.17.0-5e8cf70
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 +19886 -18589
- package/package.json +6 -3
- package/readme.md +89 -15
- package/utils.js +165 -85
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-5e8cf70",
|
|
4
4
|
"repository": "https://github.com/drizzle-team/drizzle-kit-mirror",
|
|
5
5
|
"author": "Drizzle Team",
|
|
6
6
|
"license": "MIT",
|
|
@@ -9,12 +9,13 @@
|
|
|
9
9
|
},
|
|
10
10
|
"scripts": {
|
|
11
11
|
"migrate:old": "drizzle-kit generate:pg --out ./dev/migrations-pg --schema ./dev/migrations-pg/schema.ts",
|
|
12
|
+
"push": "node -r esbuild-register ./src/cli/index.ts push:mysql",
|
|
12
13
|
"migrate:old:mysql": "drizzle-kit generate:mysql --out ./dev/migrations-mysql --schema ./dev/migrations-mysql/schema.ts",
|
|
13
14
|
"start:pg": "node -r esbuild-register ./src/cli/index.ts generate:pg --out ./dev/migrations-pg --schema ./dev/migrations-pg/schema.ts",
|
|
14
15
|
"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/
|
|
16
|
+
"start:mysql": "node -r esbuild-register ./src/cli/index.ts generate:mysql --out ./dev/introspect-mysql --schema ./dev/introspect-mysql/schema.ts",
|
|
16
17
|
"check:pg": "node -r esbuild-register ./src/cli/index.ts check --out ./dev/migrations --dialect pg",
|
|
17
|
-
"introspect:mysql": "node -r esbuild-register ./src/cli/index.ts introspect:mysql
|
|
18
|
+
"introspect:mysql": "node -r esbuild-register ./src/cli/index.ts introspect:mysql",
|
|
18
19
|
"introspect:pg": "node -r esbuild-register ./src/cli/index.ts introspect:pg --out ./dev/introspect-pg --connectionString=postgresql://postgres@localhost:5432/introspect",
|
|
19
20
|
"up:pg": "node -r esbuild-register ./src/cli/index.ts up:pg --out ./dev/migrations-pg",
|
|
20
21
|
"up:mysql": "node -r esbuild-register ./src/cli/index.ts up:mysql --out ./dev/migrations-mysql",
|
|
@@ -55,11 +56,13 @@
|
|
|
55
56
|
"glob": "^8.1.0",
|
|
56
57
|
"hanji": "^0.0.5",
|
|
57
58
|
"json-diff": "0.9.0",
|
|
59
|
+
"minimatch": "^7.4.3",
|
|
58
60
|
"zod": "^3.20.2"
|
|
59
61
|
},
|
|
60
62
|
"devDependencies": {
|
|
61
63
|
"@types/dockerode": "^3.3.14",
|
|
62
64
|
"@types/glob": "^8.1.0",
|
|
65
|
+
"@types/minimatch": "^5.1.2",
|
|
63
66
|
"@types/node": "^18.11.15",
|
|
64
67
|
"@types/pg": "^8.6.5",
|
|
65
68
|
"@typescript-eslint/eslint-plugin": "^5.46.1",
|
package/readme.md
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
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
|
|
|
13
|
-
import { integer, pgTable, serial, text, varchar } from "drizzle-orm-
|
|
16
|
+
import { integer, pgTable, serial, text, varchar } from "drizzle-orm/pg-core";
|
|
14
17
|
|
|
15
18
|
const users = pgTable("users", {
|
|
16
19
|
id: serial("id").primaryKey(),
|
|
@@ -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
|
+
npx drizzle-kit generate:pg --out migrations-folder --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
|
-
|