Skip to content

Refactor to Drizzle ORM and add baseline schema migration#27

Merged
KyleTryon merged 2 commits intomainfrom
chore/remove-old-migrations
Apr 18, 2026
Merged

Refactor to Drizzle ORM and add baseline schema migration#27
KyleTryon merged 2 commits intomainfrom
chore/remove-old-migrations

Conversation

@KyleTryon
Copy link
Copy Markdown
Contributor

This pull request migrates the server database layer from a custom, homegrown migration system to Drizzle ORM's built-in migration system. It removes legacy migration code, adds Drizzle migrations and related scripts, and introduces a safety check to prevent using old databases without proper migration state. The Docker build and runtime are updated to include Drizzle migration files.

Database migration system migration:

  • Removed the legacy migration system by deleting runMigrations and all custom migration logic from apps/server/src/db/migrations.ts, and removed the schema_migrations table from apps/server/src/db/schema.ts. [1] [2]
  • Switched to Drizzle ORM migrations in apps/server/src/db/database.ts, using Drizzle's migrate function and referencing the Drizzle migrations folder. [1] [2]

Drizzle migration setup:

  • Added initial Drizzle migration SQL in apps/server/drizzle/20260418064431_baseline/migration.sql, recreating the schema and indexes for provider_accounts, media_sources, and provider_sessions.
  • Added a new script db:export to apps/server/package.json for exporting Drizzle migrations as SQL.

Safety and compatibility checks:

  • Added prepareDatabaseForMigrations in apps/server/src/db/migrationState.ts to detect and prevent use of pre-release databases without Drizzle migration state, requiring users to delete old data directories if detected.

Dockerfile updates:

  • Updated the Docker build and runtime to copy the Drizzle migrations folder, ensuring migrations are available in production containers. [1] [2]

@KyleTryon KyleTryon merged commit 323cfd3 into main Apr 18, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant