Database Setup
RocketFuel uses Drizzle ORM with PostgreSQL for database management. This guide covers setup, schema management, and common patterns.
PostgreSQL Options
Choose a PostgreSQL provider that fits your needs:
Local Development
docker run --name postgres \ -e POSTGRES_PASSWORD=password \ -e POSTGRES_DB=myapp \ -p 5432:5432 \ -d postgresConnection string:
DATABASE_URL="postgresql://postgres:password@localhost:5432/myapp"Install PostgreSQL using your system package manager, then:
createdb myappConnection string:
DATABASE_URL="postgresql://localhost:5432/myapp"Cloud Providers
| Provider | Best For |
|---|---|
| Neon | Serverless, auto-scaling |
| Supabase | Full backend platform |
| Railway | Simple deployments |
| PlanetScale | MySQL alternative with branching |
Schema Management
The Schema File
Your database schema is defined in src/server/db/schema.ts:
import { pgTable, text, timestamp, boolean } from "drizzle-orm/pg-core";
export const user = pgTable("user", { id: text("id").primaryKey(), name: text("name").notNull(), email: text("email").notNull().unique(), emailVerified: boolean("email_verified").notNull(), image: text("image"), createdAt: timestamp("created_at").notNull(), updatedAt: timestamp("updated_at").notNull(),});Pushing Schema Changes
During development, use push for rapid iteration:
npx drizzle-kit pushUsing Migrations
For production deployments:
-
Generate migration
Terminal window npx drizzle-kit generateThis creates a SQL migration file in
drizzle/. -
Review the migration
Check the generated SQL before applying.
-
Apply migration
Terminal window npx drizzle-kit migrate
Drizzle Studio
Inspect your database with the built-in GUI:
npx drizzle-kit studioOpens at https://local.drizzle.studio.
Querying Data
Basic Queries
import { db } from "@/server/db";import { user } from "@/server/db/schema";import { eq } from "drizzle-orm";
// Select allconst users = await db.select().from(user);
// Select with filterconst activeUsers = await db .select() .from(user) .where(eq(user.emailVerified, true));
// Insertawait db.insert(user).values({ id: "user_123", name: "John Doe", email: "john@example.com", emailVerified: false, createdAt: new Date(), updatedAt: new Date(),});
// Updateawait db .update(user) .set({ emailVerified: true }) .where(eq(user.id, "user_123"));
// Deleteawait db.delete(user).where(eq(user.id, "user_123"));