drizzle-kit 0.23.2-3d4e79a → 0.23.2-ab12f1d

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. package/README.md +79 -0
  2. package/bin.cjs +3909 -49628
  3. package/package.json +25 -2
package/README.md CHANGED
@@ -0,0 +1,79 @@
1
+ ## Drizzle Kit
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 deletions and renames by prompting user input.
4
+ <https://github.com/drizzle-team/drizzle-kit-mirror> - is a mirror repository for issues.
5
+
6
+ ## Documentation
7
+
8
+ Check the full documenation on [the website](https://orm.drizzle.team/kit-docs/overview)
9
+
10
+ ### How it works
11
+
12
+ `drizzle-kit` will traverse `schema folder` or `schema file`, generate schema snapshot and compare it to the previous version, if there's one.
13
+ Based on the difference it will generate all needed SQL migrations and if there are any `automatically unresolvable` cases like `renames` it will prompt user for input.
14
+
15
+ For schema file:
16
+
17
+ ```typescript
18
+ // ./src/db/schema.ts
19
+
20
+ import { integer, pgTable, serial, text, varchar } from "drizzle-orm/pg-core";
21
+
22
+ const users = pgTable("users", {
23
+ id: serial("id").primaryKey(),
24
+ fullName: varchar("full_name", { length: 256 }),
25
+ }, (table) => ({
26
+ nameIdx: index("name_idx", table.fullName),
27
+ })
28
+ );
29
+
30
+ export const authOtp = pgTable("auth_otp", {
31
+ id: serial("id").primaryKey(),
32
+ phone: varchar("phone", { length: 256 }),
33
+ userId: integer("user_id").references(() => users.id),
34
+ });
35
+ ```
36
+
37
+ It will generate:
38
+
39
+ ```SQL
40
+ CREATE TABLE IF NOT EXISTS auth_otp (
41
+ "id" SERIAL PRIMARY KEY,
42
+ "phone" character varying(256),
43
+ "user_id" INT
44
+ );
45
+
46
+ CREATE TABLE IF NOT EXISTS users (
47
+ "id" SERIAL PRIMARY KEY,
48
+ "full_name" character varying(256)
49
+ );
50
+
51
+ DO $$ BEGIN
52
+ ALTER TABLE auth_otp ADD CONSTRAINT auth_otp_user_id_fkey FOREIGN KEY ("user_id") REFERENCES users(id);
53
+ EXCEPTION
54
+ WHEN duplicate_object THEN null;
55
+ END $$;
56
+
57
+ CREATE INDEX IF NOT EXISTS users_full_name_index ON users (full_name);
58
+ ```
59
+
60
+ ### Installation & configuration
61
+
62
+ ```shell
63
+ npm install -D drizzle-kit
64
+ ```
65
+
66
+ Running with CLI options
67
+
68
+ ```jsonc
69
+ // package.json
70
+ {
71
+ "scripts": {
72
+ "generate": "drizzle-kit generate --out migrations-folder --schema src/db/schema.ts"
73
+ }
74
+ }
75
+ ```
76
+
77
+ ```shell
78
+ npm run generate
79
+ ```