manubier
manubier
Explore posts from servers
CDCloudflare Developers
Created by manubier on 10/11/2024 in #general-help
Seeking Best Practices for Using Drizzle ORM with D1, Especially for Migrations
Hi everyone, I’m currently working on a project using Drizzle ORM with D1, and I’ve encountered some challenges around handling migrations. I’d really appreciate any insights or best practices from those who have navigated this before. Here are some of the specific questions and areas where I’m looking for guidance: 1. Creating Migrations: - What are the best practices for generating migration files? - Should I be using the Drizzle commands like DrizzleKit generate for this, or should I stick to using Wrangler commands? 2. Applying Migrations Locally and in Production: - When applying migrations, is it better to use the Wrangler command or the DrizzleKit migrate command? - I’ve been using DrizzleKit generate to create migration files, then applying them with Wrangler, which has worked both locally and in production. However, I recently encountered a situation where a migration applied successfully locally but failed when I tried to apply it in production. - Additionally, Wrangler doesn’t seem to have a command for dropping migrations. I used Drizzle drop, but since the initial application was through Wrangler, it didn’t properly adjust my database. This left my local database in an odd state, which I resolved by recreating it, but I’m hoping to avoid this in the future. What’s the recommended approach for dropping or reverting migrations properly? 3. Integrating Migrations into CI/CD Pipeline: - How can I integrate the migration process into my CI/CD pipeline using GitHub Actions? - I attempted to automate applying migrations in production through GitHub Actions but ran into some difficulties. Has anyone successfully set this up, and if so, could you share your approach? Overall, I think there’s a need for a comprehensive guide on best practices for using Drizzle ORM with D1, particularly around handling migrations. If anyone has advice or experience to share, I’d be incredibly grateful! Thanks in advance!
5 replies