Skip to content

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

Terminal window
docker run --name postgres \
-e POSTGRES_PASSWORD=password \
-e POSTGRES_DB=myapp \
-p 5432:5432 \
-d postgres

Connection string:

DATABASE_URL="postgresql://postgres:password@localhost:5432/myapp"

Cloud Providers

ProviderBest For
NeonServerless, auto-scaling
SupabaseFull backend platform
RailwaySimple deployments
PlanetScaleMySQL 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:

Terminal window
npx drizzle-kit push

Using Migrations

For production deployments:

  1. Generate migration

    Terminal window
    npx drizzle-kit generate

    This creates a SQL migration file in drizzle/.

  2. Review the migration

    Check the generated SQL before applying.

  3. Apply migration

    Terminal window
    npx drizzle-kit migrate

Drizzle Studio

Inspect your database with the built-in GUI:

Terminal window
npx drizzle-kit studio

Opens 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 all
const users = await db.select().from(user);
// Select with filter
const activeUsers = await db
.select()
.from(user)
.where(eq(user.emailVerified, true));
// Insert
await db.insert(user).values({
id: "user_123",
name: "John Doe",
email: "john@example.com",
emailVerified: false,
createdAt: new Date(),
updatedAt: new Date(),
});
// Update
await db
.update(user)
.set({ emailVerified: true })
.where(eq(user.id, "user_123"));
// Delete
await db.delete(user).where(eq(user.id, "user_123"));