Quick start

Lets build a quick start app with PostgreSQL + postgresjs and run our first migration.

The first thing we need to do is to install drizzle-orm and drizzle-kit:

npm i drizzle-orm postgres
npm i -D drizzle-kit

Lets declare our schema.ts:

πŸ“¦ <project root>
 β”œ ...
 β”œ πŸ“‚ src
 β”‚ β”” πŸ“œ schema.ts
 β”” πŸ“œ package.json
import { serial, text, timestamp, pgTable } from "drizzle-orm/pg-core";

export const user = pgTable("user", {
  id: serial("id"),
  name: text("name"),
  email: text("email"),
  password: text("password"),
  role: text("role").$type<"admin" | "customer">(),
  createdAt: timestamp("created_at"),
  updatedAt: timestamp("updated_at"),

Now lets add drizzle configuration file:

πŸ“¦ <project root>
 β”œ ...
 β”œ πŸ“‚ src
 β”œ πŸ“œ drizzle.config.ts
 β”” πŸ“œ package.json
import { defineConfig } from "drizzle-kit";

export default defineConfig({
  dialect: "postgresql",
  schema: "./src/schema.ts",
  out: "./drizzle",

Add generate and migrate commands to package.json and run our first migrations generation:

  "name": "first time?",
  "version": "0.0.1",
  "scripts": {
    "generate": "drizzle-kit generate",
    "migrate": "drizzle-kit migrate"
$ npm run generate

[βœ“] Your SQL migration file ➜ drizzle/0000_pale_mister_fear.sql πŸš€

Done! We now have our first SQL migration file πŸ₯³

πŸ“¦ <project root>
 β”œ πŸ“‚ drizzle
 β”‚ β”œ πŸ“‚ _meta
 β”‚ β”” πŸ“œ 0000_pale_mister_fear.sql
 β”œ πŸ“‚ src
 β”œ πŸ“œ drizzle.config.ts
 β”” πŸ“œ package.json

Now lets run our first migration to the database:

$ npm run migrate

That’s it, folks!

My personal congratulations πŸŽ‰