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
yarn
pnpm
bun
npm i drizzle-orm@rc postgres
npm i -D drizzle-kit@rc
Lets declare our schema.ts:
π¦ <project root>
β ...
β π src
β β π schema.ts
β π package.jsonimport { 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.jsonimport { 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/20242409125510_pale_mister_fear/migration.sql πDone! We now have our first SQL migration file π₯³
π¦ <project root>
β π drizzle
β β π 20242409125510_pale_mister_fear
β π src
β π drizzle.config.ts
β π package.jsonNow lets run our first migration to the database:
$ npm run migrateThatβs it, folks!
My personal congratulations π