CoolFace
Apppublic

AK-21/Graphite-Industrial-Intelligence

sourceHugging Faceupdated 3mo agoView on Hugging Face
0likes
README.md80 linesDownload Raw Back to drizzle-kit
1## Drizzle Kit2 3Drizzle Kit is a CLI migrator tool for Drizzle ORM. It is probably the 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## Documentation7 8Check the full documentation on [the website](https://orm.drizzle.team/kit-docs/overview).9 10### How it works11 12Drizzle Kit traverses a schema module and generates a snapshot to compare with the previous version, if there is one.13Based on the difference, it will generate all needed SQL migrations. If there are any cases that can't be resolved automatically, such as renames, it will prompt the user for input.14 15For example, for this schema module:16 17```typescript18// src/db/schema.ts19 20import { integer, pgTable, serial, text, varchar } from "drizzle-orm/pg-core";21 22const 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 30export 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 37It will generate:38 39```SQL40CREATE TABLE IF NOT EXISTS auth_otp (41 "id" SERIAL PRIMARY KEY,42 "phone" character varying(256),43 "user_id" INT44);45 46CREATE TABLE IF NOT EXISTS users (47 "id" SERIAL PRIMARY KEY,48 "full_name" character varying(256)49);50 51DO $$ BEGIN52 ALTER TABLE auth_otp ADD CONSTRAINT auth_otp_user_id_fkey FOREIGN KEY ("user_id") REFERENCES users(id);53EXCEPTION54 WHEN duplicate_object THEN null;55END $$;56 57CREATE INDEX IF NOT EXISTS users_full_name_index ON users (full_name);58```59 60### Installation & configuration61 62```shell63npm install -D drizzle-kit64```65 66Running with CLI options:67 68```jsonc69// package.json70{71 "scripts": {72  "generate": "drizzle-kit generate --out migrations-folder --schema src/db/schema.ts"73 }74}75```76 77```shell78npm run generate79```80