run app locally:
cd apps/api
bun dev:turso
# new terminal
bun run devcd apps/web-app
bun run devAsyncStatus uses Drizzle ORM for database management with SQLite/Turso. When making changes to the database schema, you need to create and apply migrations.
- Schema Definition: Database tables are defined in
apps/api/src/db/schema.ts - Migration Generation: After changing the schema, you generate SQL migration files
- Migration Application: Apply the migrations to update the database structure
Edit apps/api/src/db/schema.ts to make your schema changes. For example, to add a new field to a table:
export const member = sqliteTable(
"member",
{
id: text("id").primaryKey(),
// ... existing fields
// Add a new field
newField: text("new_field"),
}
// ... indexes
);Run the migration generation script from the API directory:
cd apps/api
bun run migrate:generateThis will create a new SQL migration file in the apps/api/drizzle directory (e.g., 0006_new_migration.sql).
Apply the migration to update the database:
cd apps/api
bun run migrateHere's an example of how we added the slackUsername field to the member table:
-
Updated the schema in
apps/api/src/db/schema.ts:export const member = sqliteTable( "member", { // ... existing fields // Optional Slack username - nullable by default slackUsername: text("slack_username"), // ... other fields } // ... indexes );
-
Generated the migration:
cd apps/api bun run migrate:generateThis created
apps/api/drizzle/0005_flashy_polaris.sqlwith:ALTER TABLE `member` ADD `slack_username` text;
-
Applied the migration:
cd apps/api bun run migrate
- Migration not applying: Make sure your local database is running (
bun dev:turso) - Schema errors: Check the Drizzle ORM documentation for correct type definitions
- Conflict errors: If you have conflicts between local and remote databases, you may need to reset your local database or use
drizzle-kit push --force