ποΈ Database
ποΈ Extending database schema
Follow the steps below to extend your database schema.
All commands can be ran from the top level (project root) directory.
Define schema
Define your Drizzle (opens in a new tab) schema in /packages/api/src/db/schema.ts
.
Generate migration
Generate migration files using the pnpm generate
command.
# Generate types & migrations
pnpm generate
Run migrations
Run the schema migration using the pnpm migrate:local
command.
# Migrate local database
pnpm migrate:local
# Migrate database hosted on Cloudflare D1
pnpm migrate
Create seed data
Modify the .sql file at /packages/api/seed/seed.sql
with your seed data. ChatGPT or faker.js are great tools for generating seed data.
Seed data
Seed the database using pnpm seed:local
command.
# Seed local database
pnpm seed:local
# Seed database hosted by Cloudflare D1
pnpm seed
To run the steps on the Cloudflare D1 hosted database, drop the :local
suffix.
π¦ Migrations
Here are helpful commands for migrating your SQLite / Cloudflare D1 database schema.
# Generate migrations
pnpm generate
# Run migrations on local
pnpm migrate:local
# Run migrations on database hosted by Cloudflare D1
pnpm migrate
π¦ Seeding data
Here are helpful commands for seeding your SQLite / Cloudflare D1 database with data.
# Run seeding on local
pnpm seed:local
# Run seeding on production
pnpm seed