drizzle-kit 0.12.1 → 0.12.4
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 +8 -8
- package/package.json +1 -1
- package/readme.md +100 -0
package/index.js
CHANGED
|
@@ -17969,7 +17969,7 @@ var PgSquasher = {
|
|
|
17969
17969
|
const result = index.parse({
|
|
17970
17970
|
name,
|
|
17971
17971
|
columns: columnsString.split(","),
|
|
17972
|
-
isUnique:
|
|
17972
|
+
isUnique: isUnique === "true"
|
|
17973
17973
|
});
|
|
17974
17974
|
return result;
|
|
17975
17975
|
},
|
|
@@ -18032,7 +18032,7 @@ var generatePgSnapshot = (tables, enums) => {
|
|
|
18032
18032
|
if (column3.default instanceof import_sql.SQL) {
|
|
18033
18033
|
columnToSet.default = column3.default.queryChunks.map((it) => {
|
|
18034
18034
|
if (typeof it === "string") {
|
|
18035
|
-
return
|
|
18035
|
+
return `${it}`;
|
|
18036
18036
|
}
|
|
18037
18037
|
throw new Error();
|
|
18038
18038
|
}).join();
|
|
@@ -18119,7 +18119,7 @@ var generateMySqlSnapshot = (tables, enums) => {
|
|
|
18119
18119
|
if (column3.default instanceof import_sql2.SQL) {
|
|
18120
18120
|
columnToSet.default = column3.default.queryChunks.map((it) => {
|
|
18121
18121
|
if (typeof it === "string") {
|
|
18122
|
-
return
|
|
18122
|
+
return `${it}`;
|
|
18123
18123
|
}
|
|
18124
18124
|
throw new Error();
|
|
18125
18125
|
}).join();
|
|
@@ -18460,8 +18460,8 @@ var PgCreateForeignKeyConvertor = class extends Convertor {
|
|
|
18460
18460
|
}
|
|
18461
18461
|
convert(statement) {
|
|
18462
18462
|
const { name, tableFrom, tableTo, columnsFrom, columnsTo, onDelete, onUpdate } = PgSquasher.unsquashFK(statement.data);
|
|
18463
|
-
const onDeleteStatement = onDelete || "";
|
|
18464
|
-
const onUpdateStatement = onUpdate || "";
|
|
18463
|
+
const onDeleteStatement = `ON DELETE ${onDelete}` || "";
|
|
18464
|
+
const onUpdateStatement = `ON UPDATE ${onUpdate}` || "";
|
|
18465
18465
|
const fromColumnsString = columnsFrom.map((it) => `"${it}"`).join(",");
|
|
18466
18466
|
const toColumnsString = columnsTo.map((it) => `"${it}"`).join(",");
|
|
18467
18467
|
const alterStatement = `ALTER TABLE ${tableFrom} ADD CONSTRAINT ${name} FOREIGN KEY (${fromColumnsString}) REFERENCES ${tableTo}(${toColumnsString}) ${onDeleteStatement} ${onUpdateStatement}`.replace(/ +/g, " ").trim();
|
|
@@ -18479,8 +18479,8 @@ var MySqlCreateForeignKeyConvertor = class extends Convertor {
|
|
|
18479
18479
|
}
|
|
18480
18480
|
convert(statement) {
|
|
18481
18481
|
const { name, tableFrom, tableTo, columnsFrom, columnsTo, onDelete, onUpdate } = PgSquasher.unsquashFK(statement.data);
|
|
18482
|
-
const onDeleteStatement = onDelete || "";
|
|
18483
|
-
const onUpdateStatement = onUpdate || "";
|
|
18482
|
+
const onDeleteStatement = `ON DELETE ${onDelete}` || "";
|
|
18483
|
+
const onUpdateStatement = `ON UPDATE ${onUpdate}` || "";
|
|
18484
18484
|
const fromColumnsString = columnsFrom.map((it) => `\`${it}\``).join(",");
|
|
18485
18485
|
const toColumnsString = columnsTo.map((it) => `\`${it}\``).join(",");
|
|
18486
18486
|
return `ALTER TABLE ${tableFrom} ADD CONSTRAINT ${name} FOREIGN KEY (${fromColumnsString}) REFERENCES ${tableTo}(${toColumnsString}) ${onDeleteStatement} ${onUpdateStatement};`.replace(/ +/g, " ").trim();
|
|
@@ -19008,7 +19008,7 @@ var MySqlSquasher = {
|
|
|
19008
19008
|
const result = index2.parse({
|
|
19009
19009
|
name,
|
|
19010
19010
|
columns: columnsString.split(","),
|
|
19011
|
-
isUnique:
|
|
19011
|
+
isUnique: isUnique === "true",
|
|
19012
19012
|
using,
|
|
19013
19013
|
algorithm,
|
|
19014
19014
|
lock
|
package/package.json
CHANGED
package/readme.md
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
## Drizzle Kit
|
|
2
|
+
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
|
+
|
|
5
|
+
### How it works
|
|
6
|
+
`drizzle-kit` will traverse `schema folder` or `schema file`, generate schema snapshot and compare it to the previous version(if there's one).\
|
|
7
|
+
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
|
+
|
|
9
|
+
For schema file:
|
|
10
|
+
```typescript
|
|
11
|
+
// ./src/db/schema.ts
|
|
12
|
+
|
|
13
|
+
import { integer, pgTable, serial, text, varchar } from "drizzle-orm-pg";
|
|
14
|
+
|
|
15
|
+
const users = pgTable("users", {
|
|
16
|
+
id: serial("id").primaryKey(),
|
|
17
|
+
fullName: varchar("full_name", { length: 256 }),
|
|
18
|
+
}, (table) => ({
|
|
19
|
+
nameIdx: index("name_idx", table.fullName),
|
|
20
|
+
})
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
export const authOtp = pgTable("auth_otp", {
|
|
24
|
+
id: serial("id").primaryKey(),
|
|
25
|
+
phone: varchar("phone", { length: 256 }),
|
|
26
|
+
userId: integer("user_id").references(() => users.id),
|
|
27
|
+
});
|
|
28
|
+
```
|
|
29
|
+
It will generate:
|
|
30
|
+
```SQL
|
|
31
|
+
CREATE TABLE IF NOT EXISTS auth_otp (
|
|
32
|
+
"id" SERIAL PRIMARY KEY,
|
|
33
|
+
"phone" character varying(256),
|
|
34
|
+
"user_id" INT
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
CREATE TABLE IF NOT EXISTS users (
|
|
38
|
+
"id" SERIAL PRIMARY KEY,
|
|
39
|
+
"full_name" character varying(256)
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
DO $$ BEGIN
|
|
43
|
+
ALTER TABLE auth_otp ADD CONSTRAINT auth_otp_user_id_fkey FOREIGN KEY ("user_id") REFERENCES users(id);
|
|
44
|
+
EXCEPTION
|
|
45
|
+
WHEN duplicate_object THEN null;
|
|
46
|
+
END $$;
|
|
47
|
+
|
|
48
|
+
CREATE INDEX IF NOT EXISTS users_full_name_index ON users (full_name);
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Installation & configuration
|
|
52
|
+
```shell
|
|
53
|
+
$ npm install -D drizzle-kit
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Running with CLI options
|
|
57
|
+
```shell
|
|
58
|
+
$ npm exec drizzle-kit generate --out migrations-folder --dialect pg --schema src/db/schema.ts
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Or put your file to `drizzle.config.json` configuration file:
|
|
62
|
+
```json
|
|
63
|
+
{
|
|
64
|
+
"dialect": "pg",
|
|
65
|
+
"out": "./migrations-folder",
|
|
66
|
+
"schema": "./src/db"
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
---
|
|
70
|
+
### List of commands
|
|
71
|
+
**`$ drizzle-kit generate`** - generates SQL migrations based on .ts schema\
|
|
72
|
+
`--config` [optional defalut=drizzle.config.json] path to an optional config file\
|
|
73
|
+
`--dialect` [optional default=pg] database dialect, one of -> pg, mysql, sqlite\
|
|
74
|
+
`--schema` path to a schema file or folder with multiple schema files\
|
|
75
|
+
`--out` [optional default=drizzle/] place where to store migration files\
|
|
76
|
+
```shell
|
|
77
|
+
$ drizzle-kit generate
|
|
78
|
+
## runs generate command with drizzle.config.json
|
|
79
|
+
|
|
80
|
+
$ drizzle-kit generate --config custom.config.json
|
|
81
|
+
## runs generate command with custom.config.json
|
|
82
|
+
|
|
83
|
+
$ drizzle-kit generate --dialect pg --schema src/schema.ts
|
|
84
|
+
## runs generate command and outputs results to ./drizzle
|
|
85
|
+
|
|
86
|
+
$ drizzle-kit generate --dialect .. --schema .. --out ./migration-folder
|
|
87
|
+
## runs generate command and outputs results to ./migration-folder
|
|
88
|
+
```
|
|
89
|
+
**`$ drizzle-kit up`** - updates stale snapshots
|
|
90
|
+
`--config` [optional defalut=drizzle.config.json] path to an optional config file\
|
|
91
|
+
`--dialect` [optional default=pg] database dialect, one of -> pg, mysql, sqlite\
|
|
92
|
+
`--schema` path to a schema file or folder with multiple schema files\
|
|
93
|
+
|
|
94
|
+
**`$ drizzle-kit check`** - checks for collisions
|
|
95
|
+
`--config` [optional defalut=drizzle.config.json] path to an optional config file\
|
|
96
|
+
`--dialect` [optional default=pg] database dialect, one of -> pg, mysql, sqlite\
|
|
97
|
+
`--schema` path to a schema file or folder with multiple schema files\
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
|