You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I wanted to ask how you typically handle database migrations in your Remix/RR7 apps, especially during deployment to platforms like Fly.io.
I ran into an issue when attempting to use drizzle-kit for migrations on Fly.io. Since drizzle-kit is in devDependencies, it is not available on my prod image. And, installing drizzle-kit as a production dependency felt like overkill since it’s primarily a development tool.
To work around this, I ended up implementing the following solution:
1. Custom Migration Script:
I created a script (database/migrate.ts) to run migrations programmatically using Drizzle ORM:
import{drizzle}from"drizzle-orm/postgres-js";import{migrate}from"drizzle-orm/postgres-js/migrator";importpostgresfrom"postgres";constmigrationsClient=postgres(process.env.DATABASE_URL,{max: 1});asyncfunctionrunMigrations(){try{constdb=drizzle(migrationsClient);awaitmigrate(db,{migrationsFolder: "drizzle"});console.log("Migrations ran successfully.");}catch(error){console.error("Error running migrations:",error);process.exit(1);}finally{awaitmigrationsClient.end();process.exit(0);}}voidrunMigrations();
2. Fly.io Deployment:
I configured Fly.io’s release_command to execute the script during deployment:
Hi there 👋
I wanted to ask how you typically handle database migrations in your Remix/RR7 apps, especially during deployment to platforms like Fly.io.
I ran into an issue when attempting to use
drizzle-kit
for migrations on Fly.io. Sincedrizzle-kit
is indevDependencies
, it is not available on my prod image. And, installingdrizzle-kit
as a production dependency felt like overkill since it’s primarily a development tool.To work around this, I ended up implementing the following solution:
1. Custom Migration Script:
I created a script (
database/migrate.ts
) to run migrations programmatically using Drizzle ORM:2. Fly.io Deployment:
I configured Fly.io’s
release_command
to execute the script during deployment:3. Dockerfile:
Here’s the Dockerfile I’m using for the app:
This approach works, but I’m curious to know your thoughts:
drizzle-kit
directly, and if so, how do you manage its usage in production environments?Looking forward to your insights—thank you in advance for your help!
The text was updated successfully, but these errors were encountered: