drizzle-kit 0.19.0-c1c76b7 → 0.19.0-e63c5cb
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.cjs +900 -314
- package/index.d.ts +35 -9
- package/package.json +3 -2
- package/readme.md +0 -153
- package/utils.js +9 -5
package/index.d.ts
CHANGED
|
@@ -5,22 +5,18 @@ export type Config = {
|
|
|
5
5
|
schema?: string | string[];
|
|
6
6
|
verbose?: boolean | undefined;
|
|
7
7
|
strict?: boolean | undefined;
|
|
8
|
+
} & {
|
|
9
|
+
introspect?: {
|
|
10
|
+
casing: "camel" | "preserve";
|
|
11
|
+
};
|
|
8
12
|
} & ({
|
|
9
|
-
port?: number | undefined;
|
|
10
|
-
password?: string | undefined;
|
|
11
|
-
host: string;
|
|
12
|
-
user: string;
|
|
13
|
-
database: string;
|
|
14
|
-
} | {
|
|
15
|
-
connectionString: string;
|
|
16
|
-
} | {
|
|
17
13
|
driver: "turso";
|
|
18
14
|
dbCredentials: {
|
|
19
15
|
url: string;
|
|
20
16
|
authToken?: string;
|
|
21
17
|
};
|
|
22
18
|
} | {
|
|
23
|
-
driver: "sqlite";
|
|
19
|
+
driver: "better-sqlite";
|
|
24
20
|
dbCredentials: {
|
|
25
21
|
url: string;
|
|
26
22
|
};
|
|
@@ -29,4 +25,34 @@ export type Config = {
|
|
|
29
25
|
dbCredentials: {
|
|
30
26
|
url: string;
|
|
31
27
|
};
|
|
28
|
+
} | {
|
|
29
|
+
driver: "pg";
|
|
30
|
+
dbCredentials: {
|
|
31
|
+
host: string;
|
|
32
|
+
port?: number;
|
|
33
|
+
user?: string;
|
|
34
|
+
password?: string;
|
|
35
|
+
database: string;
|
|
36
|
+
ssl?: boolean;
|
|
37
|
+
};
|
|
38
|
+
} | {
|
|
39
|
+
driver: "pg";
|
|
40
|
+
dbCredentials: {
|
|
41
|
+
connectionString: string;
|
|
42
|
+
};
|
|
43
|
+
} | {
|
|
44
|
+
driver: "mysql2";
|
|
45
|
+
dbCredentials: {
|
|
46
|
+
host: string;
|
|
47
|
+
port?: number;
|
|
48
|
+
user?: string;
|
|
49
|
+
password?: string;
|
|
50
|
+
database: string;
|
|
51
|
+
connectionString: string;
|
|
52
|
+
};
|
|
53
|
+
} | {
|
|
54
|
+
driver: "mysql2";
|
|
55
|
+
dbCredentials: {
|
|
56
|
+
connectionString: string;
|
|
57
|
+
};
|
|
32
58
|
} | {});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "drizzle-kit",
|
|
3
|
-
"version": "0.19.0-
|
|
3
|
+
"version": "0.19.0-e63c5cb",
|
|
4
4
|
"repository": "https://github.com/drizzle-team/drizzle-kit-mirror",
|
|
5
5
|
"author": "Drizzle Team",
|
|
6
6
|
"license": "MIT",
|
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
"sim:sqlite": "node -r esbuild-register ./dev/sqlite/index.ts",
|
|
35
35
|
"test": "ava test --timeout=60s",
|
|
36
36
|
"build": "rm -rf ./dist && tsx build.ts && tsc -p tsconfig.cli-types.json",
|
|
37
|
+
"build:dev": "rm -rf ./dist && tsx build.dev.ts && tsc -p tsconfig.cli-types.json && chmod +x ./dist/index.cjs",
|
|
37
38
|
"pack": "build && package",
|
|
38
39
|
"tsc": "tsc -p tsconfig.build.json",
|
|
39
40
|
"pub": "cp package.json readme.md dist/ && cd dist && npm publish"
|
|
@@ -74,7 +75,7 @@
|
|
|
74
75
|
"better-sqlite3": "^8.4.0",
|
|
75
76
|
"dockerode": "^3.3.4",
|
|
76
77
|
"dotenv": "^16.0.3",
|
|
77
|
-
"drizzle-orm": "0.
|
|
78
|
+
"drizzle-orm": "0.27.0-56b9edc",
|
|
78
79
|
"esbuild": "^0.17.19",
|
|
79
80
|
"esbuild-register": "^3.4.2",
|
|
80
81
|
"eslint": "^8.29.0",
|
package/readme.md
CHANGED
|
@@ -77,156 +77,3 @@ Running with CLI options
|
|
|
77
77
|
```shell
|
|
78
78
|
npm run generate
|
|
79
79
|
```
|
|
80
|
-
|
|
81
|
-
### Configuration
|
|
82
|
-
|
|
83
|
-
Instead of passing arguments to the CLI commands, you can also create a `drizzle.config.json` configuration file:
|
|
84
|
-
|
|
85
|
-
```json
|
|
86
|
-
{
|
|
87
|
-
"out": "./migrations-folder",
|
|
88
|
-
"schema": "./src/db",
|
|
89
|
-
"breakpoints": false
|
|
90
|
-
}
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
* `out` - path to the output directory where migrations will be saved,
|
|
94
|
-
* `schema` - path to TypeScript schema file or folder with multiple schema files,
|
|
95
|
-
* `breakpoints` - whether to execute each statement in the migrations individually. Set to `true` if you are using SQLite or MySQL (as they don't support multiple DDL statements in a transaction).
|
|
96
|
-
|
|
97
|
-
---
|
|
98
|
-
|
|
99
|
-
## Upgrading to 0.17.0
|
|
100
|
-
|
|
101
|
-
Before running any new migrations `drizzle-kit` will ask you to upgrade first
|
|
102
|
-
|
|
103
|
-
Migration file structure < 0.17.0
|
|
104
|
-
|
|
105
|
-
```plaintext
|
|
106
|
-
📦 <project root>
|
|
107
|
-
└ 📂 migrations
|
|
108
|
-
└ 📂 20221207174503
|
|
109
|
-
├ 📜 migration.sql
|
|
110
|
-
├ 📜 snapshot.json
|
|
111
|
-
└ 📂 20230101104503
|
|
112
|
-
├ 📜 migration.sql
|
|
113
|
-
├ 📜 snapshot.json
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
Migration file structure >= 0.17.0
|
|
117
|
-
|
|
118
|
-
```plaintext
|
|
119
|
-
📦 <project root>
|
|
120
|
-
└ 📂 migrations
|
|
121
|
-
└ 📂 meta
|
|
122
|
-
├ 📜 _journal.json
|
|
123
|
-
├ 📜 0000_snapshot.json
|
|
124
|
-
├ 📜 0001_snapshot.json
|
|
125
|
-
└ 📜 0000_icy_stranger.sql
|
|
126
|
-
└ 📜 0001_strange_avengers.sql
|
|
127
|
-
```
|
|
128
|
-
|
|
129
|
-
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
|
|
130
|
-
|
|
131
|
-

|
|
132
|
-
---
|
|
133
|
-
|
|
134
|
-
## List of commands
|
|
135
|
-
|
|
136
|
-
### Generate SQL migrations based on current .ts schema
|
|
137
|
-
|
|
138
|
-
---
|
|
139
|
-
|
|
140
|
-
**`$ drizzle-kit generate:pg`** \
|
|
141
|
-
**`$ drizzle-kit generate:mysql`** \
|
|
142
|
-
**`$ drizzle-kit generate:sqlite`**
|
|
143
|
-
|
|
144
|
-
`--config` [optional default=drizzle.config.json] config file path\
|
|
145
|
-
`--schema` path to typescript schema file or folder with multiple schema files\
|
|
146
|
-
`--out` [optional default=drizzle/] migrations folder\
|
|
147
|
-
`--breakpoints` [optional default=false] whether to execute each statement in the migrations individually\
|
|
148
|
-
|
|
149
|
-
```shell
|
|
150
|
-
$ drizzle-kit generate:pg
|
|
151
|
-
## runs generate command with drizzle.config.json
|
|
152
|
-
|
|
153
|
-
$ drizzle-kit generate:pg --config=./custom.config.json
|
|
154
|
-
## runs generate command with custom.config.json
|
|
155
|
-
|
|
156
|
-
$ drizzle-kit generate:pg --schema=./src/schema.ts
|
|
157
|
-
## runs generate command and outputs results to ./drizzle
|
|
158
|
-
|
|
159
|
-
$ drizzle-kit generate:pg --schema=./src/schema.ts --out=./migrations/
|
|
160
|
-
## runs generate command and outputs results to ./migration
|
|
161
|
-
```
|
|
162
|
-
|
|
163
|
-
**Generate an empty SQL migration with `--custom`**
|
|
164
|
-
|
|
165
|
-
```shell
|
|
166
|
-
$ drizzle-kit generate:pg --custom
|
|
167
|
-
## runs generate command and outputs an empty migration for custom SQL
|
|
168
|
-
```
|
|
169
|
-
|
|
170
|
-
### Introspect existing database and generate typescript schema
|
|
171
|
-
|
|
172
|
-
---
|
|
173
|
-
|
|
174
|
-
**`$ drizzle-kit introspect:pg`** \
|
|
175
|
-
**`$ drizzle-kit introspect:mysql`**
|
|
176
|
-
|
|
177
|
-
```shell
|
|
178
|
-
drizzle-kit introspect:pg --out=migrations/ --connectionString=postgresql://user:pass@host:port/db_name
|
|
179
|
-
|
|
180
|
-
drizzle-kit introspect:pg --out=migrations/ --host=0.0.0.0 --port=5432 --user=postgres --password=pass --database=db_name --ssl
|
|
181
|
-
```
|
|
182
|
-
|
|
183
|
-

|
|
184
|
-
|
|
185
|
-
### Update stale snapshots
|
|
186
|
-
|
|
187
|
-
---
|
|
188
|
-
|
|
189
|
-
**`$ drizzle-kit up:pg`** \
|
|
190
|
-
**`$ drizzle-kit up:mysql`** \
|
|
191
|
-
**`$ drizzle-kit up:sqlite`**
|
|
192
|
-
|
|
193
|
-
`--out` [optional] migrations folder\
|
|
194
|
-
`--config` [optional default=drizzle.config.json] config file path
|
|
195
|
-
|
|
196
|
-
```shell
|
|
197
|
-
## migrations folder is taken from drizzle.config.json
|
|
198
|
-
drizzle-kit up:mysql
|
|
199
|
-
|
|
200
|
-
drizzle-kit up:mysql --out=migrations/
|
|
201
|
-
```
|
|
202
|
-
|
|
203
|
-

|
|
204
|
-
|
|
205
|
-
### Drop migration
|
|
206
|
-
|
|
207
|
-
---
|
|
208
|
-
|
|
209
|
-
**`$ drizzle-kit drop`**
|
|
210
|
-
|
|
211
|
-
`--out` [optional] migrations folder\
|
|
212
|
-
`--config` [optional default=drizzle.config.json] config file path
|
|
213
|
-
|
|
214
|
-

|
|
215
|
-
|
|
216
|
-
### Migrations collisions check
|
|
217
|
-
|
|
218
|
-
---
|
|
219
|
-
|
|
220
|
-
**`$ drizzle-kit check:pg`** \
|
|
221
|
-
**`$ drizzle-kit check:mysql`** \
|
|
222
|
-
**`$ drizzle-kit check:sqlite`**
|
|
223
|
-
|
|
224
|
-
`--out` [optional] migration folder\
|
|
225
|
-
`--config` [optional default=drizzle.config.json] config file path
|
|
226
|
-
|
|
227
|
-
```shell
|
|
228
|
-
## migrations folder is taken from drizzle.config.json
|
|
229
|
-
drizzle-kit check:pg
|
|
230
|
-
|
|
231
|
-
drizzle-kit check:pg --out=migrations/
|
|
232
|
-
```
|
package/utils.js
CHANGED
|
@@ -13602,7 +13602,7 @@ var PgCreateTableConvertor = class extends Convertor {
|
|
|
13602
13602
|
const primaryKeyStatement = column4.primaryKey ? "PRIMARY KEY" : "";
|
|
13603
13603
|
const notNullStatement = column4.notNull ? "NOT NULL" : "";
|
|
13604
13604
|
const defaultStatement = column4.default !== void 0 ? `DEFAULT ${column4.default}` : "";
|
|
13605
|
-
const type = isPgNativeType(column4.type) ? column4.type :
|
|
13605
|
+
const type = isPgNativeType(column4.type) ? column4.type : `"${column4.type}"`;
|
|
13606
13606
|
statement += " " + `"${column4.name}" ${type} ${primaryKeyStatement} ${defaultStatement} ${notNullStatement}`.replace(/ +/g, " ").trim();
|
|
13607
13607
|
statement += (i === columns.length - 1 ? "" : ",") + "\n";
|
|
13608
13608
|
}
|
|
@@ -13766,9 +13766,9 @@ var PgRenameTableConvertor = class extends Convertor {
|
|
|
13766
13766
|
return statement.type === "rename_table" && dialect3 === "pg";
|
|
13767
13767
|
}
|
|
13768
13768
|
convert(statement) {
|
|
13769
|
-
const { tableNameFrom, tableNameTo, toSchema
|
|
13770
|
-
const from =
|
|
13771
|
-
const to =
|
|
13769
|
+
const { tableNameFrom, tableNameTo, toSchema, fromSchema } = statement;
|
|
13770
|
+
const from = fromSchema ? `"${fromSchema}"."${tableNameFrom}"` : `"${tableNameFrom}"`;
|
|
13771
|
+
const to = `"${tableNameTo}"`;
|
|
13772
13772
|
return `ALTER TABLE ${from} RENAME TO ${to};`;
|
|
13773
13773
|
}
|
|
13774
13774
|
};
|
|
@@ -15678,7 +15678,11 @@ var applySnapshotsDiff = async (json1, json2, dialect3, schemasResolver, tablesR
|
|
|
15678
15678
|
}).flat();
|
|
15679
15679
|
const jsonReferencesForAllAlteredTables = allAltered.map((it) => {
|
|
15680
15680
|
const schema4 = valueFromSelfOrPatchedNew(it.schema);
|
|
15681
|
-
const forAdded =
|
|
15681
|
+
const forAdded = prepareCreateReferencesJson(
|
|
15682
|
+
it.name,
|
|
15683
|
+
schema4,
|
|
15684
|
+
it.addedForeignKeys
|
|
15685
|
+
);
|
|
15682
15686
|
const forAltered = prepareDropReferencesJson(
|
|
15683
15687
|
it.name,
|
|
15684
15688
|
schema4,
|