Skip to content

Conversation

@productdevbook
Copy link
Owner

Summary

  • Adds serverAssets config to bundle migrations in production build
  • Adds shared migration utility with Drizzle __drizzle_migrations tracking
  • Adds Nitro plugin for auto-migrate on startup (AUTO_MIGRATE env var)
  • Adds API endpoint for manual migration trigger (GET /api/cron/migrate)

Usage

Auto-migrate (default)

# Migrations run automatically on server startup
AUTO_MIGRATE=true  # or just don't set it

Manual migrate

# Disable auto-migrate
AUTO_MIGRATE=false

# Trigger manually via API
curl http://localhost:3000/api/cron/migrate

# Or with CRON_SECRET for security
curl -H "Authorization: Bearer $CRON_SECRET" http://localhost:3000/api/cron/migrate

Why this approach?

Replaces #19's manual IF NOT EXISTS approach with proper Drizzle migration tracking:

  • Drizzle tracks applied migrations in __drizzle_migrations table
  • No need to modify SQL migration files
  • Works in Docker production (migrations bundled via serverAssets)

Closes #19

Test plan

  • Build includes migrations in .output/server/chunks/raw/
  • Auto-migrate applies migrations on startup
  • Manual migrate API works with AUTO_MIGRATE=false
  • Migration tracking table records applied migrations
  • New migrations are detected and applied

🤖 Generated with Claude Code

- Add serverAssets config to bundle migrations in production
- Add migration utility with Drizzle tracking support
- Add Nitro plugin for auto-migrate on startup (AUTO_MIGRATE env)
- Add Nitro task for programmatic migration
- Add API endpoint for manual migration trigger (/api/cron/migrate)

Replaces manual IF NOT EXISTS approach with proper Drizzle migration tracking.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
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.

2 participants