drizzle-kit will traverse schema folder or schema file, 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.import { integer, pgTable, serial, text, varchar } from "drizzle-orm-pg";const users = pgTable("users", {id: serial("id").primaryKey(),fullName: varchar("full_name", { length: 256 }),}, (table) => ({nameIdx: index("name_idx", table.fullName),}));export const authOtp = pgTable("auth_otp", {id: serial("id").primaryKey(),phone: varchar("phone", { length: 256 }),userId: integer("user_id").references(() => users.id),});
Running with CLI options
Or put your file to `drizzle.config.json` configuration file:
Generate SQL migrations based on current .ts schema\
--config [optional defalut=drizzle.config.json] config file path--schema path to typescript schema file or folder with multiple schema files--out [optional default=drizzle/] migrations folder
Introspect existing database and generate typescript schema
Update stale snapshots
--out [optional] migrations folder--config [optional defalut=drizzle.config.json] config file path
Migrations collisions check
--out [optional] migration folder--config[optional defalut=drizzle.config.json] config file path