drizzle-kit 0.9.49 → 0.9.52
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 +38459 -18336
- package/package.json +12 -17
- package/.pnpm-debug.log +0 -16
- package/LICENSE +0 -674
- package/readme.md +0 -83
package/readme.md
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
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
|
-
|
|
4
|
-
### How it works
|
|
5
|
-
`drizzle-kit` will traverse `data folder` from configuration file, find all schema .ts files. Generate schema snapshot and compare it to the previous version(if there's one). 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
|
-
|
|
7
|
-
For schema file:
|
|
8
|
-
```typescript
|
|
9
|
-
import { AbstractTable } from "drizzle-orm";
|
|
10
|
-
|
|
11
|
-
export class UsersTable extends AbstractTable<UsersTable> {
|
|
12
|
-
public id = this.serial("id").primaryKey();
|
|
13
|
-
public fullName = this.varchar("full_name", { size: 256 });
|
|
14
|
-
|
|
15
|
-
public fullNameIndex = this.index(this.fullName);
|
|
16
|
-
|
|
17
|
-
public tableName(): string {
|
|
18
|
-
return "users";
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export class AuthOtpTable extends AbstractTable<AuthOtpTable> {
|
|
23
|
-
public id = this.serial("id").primaryKey();
|
|
24
|
-
public phone = this.varchar("phone", { size: 256 });
|
|
25
|
-
public userId = this.int("user_id").foreignKey(UsersTable, (t) => t.id);
|
|
26
|
-
|
|
27
|
-
public tableName(): string {
|
|
28
|
-
return "auth_otp";
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
```
|
|
32
|
-
It will generate:
|
|
33
|
-
```SQL
|
|
34
|
-
CREATE TABLE IF NOT EXISTS auth_otp (
|
|
35
|
-
"id" SERIAL PRIMARY KEY,
|
|
36
|
-
"phone" character varying(256),
|
|
37
|
-
"user_id" INT
|
|
38
|
-
);
|
|
39
|
-
|
|
40
|
-
CREATE TABLE IF NOT EXISTS users (
|
|
41
|
-
"id" SERIAL PRIMARY KEY,
|
|
42
|
-
"full_name" character varying(256)
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
DO $$ BEGIN
|
|
46
|
-
ALTER TABLE auth_otp ADD CONSTRAINT auth_otp_user_id_fkey FOREIGN KEY ("user_id") REFERENCES users(id);
|
|
47
|
-
EXCEPTION
|
|
48
|
-
WHEN duplicate_object THEN null;
|
|
49
|
-
END $$;
|
|
50
|
-
|
|
51
|
-
CREATE INDEX IF NOT EXISTS users_full_name_index ON users (full_name);
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
### Installation & configuration
|
|
55
|
-
```bash
|
|
56
|
-
npm install -g drizzle-kit
|
|
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
|
|
62
|
-
```
|
|
63
|
-
\
|
|
64
|
-
That's it, you're ready to go 🚀
|
|
65
|
-
```
|
|
66
|
-
> drizzle-kit migrate
|
|
67
|
-
```
|
|
68
|
-
\
|
|
69
|
-
You can also run migrations in project scope
|
|
70
|
-
```js
|
|
71
|
-
// package.json
|
|
72
|
-
{
|
|
73
|
-
...
|
|
74
|
-
scripts: {
|
|
75
|
-
...
|
|
76
|
-
migrate: "drizzle-kit migrate"
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
> npm run migrate
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
|