src/content/docs/quick.mdx
import Npm from "@mdx/Npm.astro";
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:
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/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.json
Now lets run our first migration to the database:
$ npm run migrate
That's it, folks!
My personal congratulations š