drizzle-kit 0.12.2 → 0.12.3
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/package.json +1 -1
- package/readme.md +61 -44
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -1,33 +1,30 @@
|
|
|
1
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
|
|
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.
|
|
3
4
|
|
|
4
5
|
### How it works
|
|
5
|
-
`drizzle-kit` will traverse `
|
|
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.
|
|
6
8
|
|
|
7
9
|
For schema file:
|
|
8
10
|
```typescript
|
|
9
|
-
|
|
11
|
+
// ./src/db/schema.ts
|
|
10
12
|
|
|
11
|
-
|
|
12
|
-
id = this.serial("id").primaryKey();
|
|
13
|
-
fullName = this.varchar("full_name", { size: 256 });
|
|
13
|
+
import { integer, pgTable, serial, text, varchar } from "drizzle-orm-pg";
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export class AuthOtpTable extends AbstractTable<AuthOtpTable> {
|
|
23
|
-
id = this.serial("id").primaryKey();
|
|
24
|
-
phone = this.varchar("phone", { size: 256 });
|
|
25
|
-
userId = this.int("user_id").foreignKey(UsersTable, (t) => t.id);
|
|
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
|
+
);
|
|
26
22
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
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
|
+
});
|
|
31
28
|
```
|
|
32
29
|
It will generate:
|
|
33
30
|
```SQL
|
|
@@ -52,32 +49,52 @@ CREATE INDEX IF NOT EXISTS users_full_name_index ON users (full_name);
|
|
|
52
49
|
```
|
|
53
50
|
|
|
54
51
|
### Installation & configuration
|
|
55
|
-
```
|
|
56
|
-
npm install -
|
|
57
|
-
```
|
|
58
|
-
Create a `drizzle.config.yml` configuration file:
|
|
59
|
-
```yaml
|
|
60
|
-
migrationRootFolder: drizzle ## all migrations will live here
|
|
61
|
-
dataFolder: './src/data' ## where are all schema .ts files
|
|
52
|
+
```shell
|
|
53
|
+
$ npm install -D drizzle-kit
|
|
62
54
|
```
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
```
|
|
66
|
-
|
|
55
|
+
|
|
56
|
+
Running with CLI options
|
|
57
|
+
```shell
|
|
58
|
+
$ npm exec drizzle-kit generate --out migrations-folder --dialect pg --schema src/db/schema.ts
|
|
67
59
|
```
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
```
|
|
71
|
-
// package.json
|
|
60
|
+
|
|
61
|
+
Or put your file to `drizzle.config.json` configuration file:
|
|
62
|
+
```json
|
|
72
63
|
{
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
migrate: "drizzle-kit migrate"
|
|
77
|
-
}
|
|
64
|
+
"dialect": "pg",
|
|
65
|
+
"out": "./migrations-folder",
|
|
66
|
+
"schema": "./src/db"
|
|
78
67
|
}
|
|
79
|
-
|
|
80
|
-
> npm run migrate
|
|
81
68
|
```
|
|
82
|
-
|
|
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
|
+
|
|
83
100
|
|