DEV Community

Alex Spinov
Alex Spinov

Posted on

Drizzle Kit Has a Free Migration Tool That Generates SQL From TypeScript — No More Manual Migrations

The Migration Problem

You change a column in your ORM model. Now you need to write a migration file. By hand. In raw SQL. And hope it matches what you changed in TypeScript.

Drizzle Kit reads your TypeScript schema and generates migrations automatically.

What Drizzle Kit Gives You

Schema as Code

import { pgTable, serial, text, integer, timestamp } from 'drizzle-orm/pg-core';

export const users = pgTable('users', {
  id: serial('id').primaryKey(),
  name: text('name').notNull(),
  email: text('email').notNull().unique(),
  age: integer('age'),
  createdAt: timestamp('created_at').defaultNow(),
});

export const posts = pgTable('posts', {
  id: serial('id').primaryKey(),
  title: text('title').notNull(),
  content: text('content'),
  authorId: integer('author_id').references(() => users.id),
});
Enter fullscreen mode Exit fullscreen mode

Auto-Generate Migrations

npx drizzle-kit generate
Enter fullscreen mode Exit fullscreen mode

Output: 0001_create_users_and_posts.sql

CREATE TABLE users (
  id SERIAL PRIMARY KEY,
  name TEXT NOT NULL,
  email TEXT NOT NULL UNIQUE,
  age INTEGER,
  created_at TIMESTAMP DEFAULT NOW()
);

CREATE TABLE posts (
  id SERIAL PRIMARY KEY,
  title TEXT NOT NULL,
  content TEXT,
  author_id INTEGER REFERENCES users(id)
);
Enter fullscreen mode Exit fullscreen mode

Schema Changes → Diffs

Add a column to your schema:

export const users = pgTable('users', {
  // ... existing columns
  role: text('role').default('user'),  // NEW
});
Enter fullscreen mode Exit fullscreen mode
npx drizzle-kit generate
Enter fullscreen mode Exit fullscreen mode

Output: 0002_add_role_to_users.sql

ALTER TABLE users ADD COLUMN role TEXT DEFAULT 'user';
Enter fullscreen mode Exit fullscreen mode

Apply Migrations

npx drizzle-kit migrate
Enter fullscreen mode Exit fullscreen mode

Drizzle Studio — Visual Database Browser

npx drizzle-kit studio
Enter fullscreen mode Exit fullscreen mode

Opens a local web UI to browse your database, edit rows, and test queries. No pgAdmin needed.

Push (No Migration Files)

npx drizzle-kit push
Enter fullscreen mode Exit fullscreen mode

For prototyping: pushes schema changes directly to the database without generating migration files.

Supports All Major Databases

  • PostgreSQL (pg, Neon, Supabase, Vercel Postgres)
  • MySQL (mysql2, PlanetScale)
  • SQLite (better-sqlite3, Turso, Cloudflare D1)

Why This Matters

Migrations should be generated, not handwritten. Drizzle Kit turns your TypeScript schema into the single source of truth for both your code AND your database.


Need external data in your database? Check out my web scraping actors on Apify Store — structured data ready for import. For custom solutions, email spinov001@gmail.com.

Top comments (0)