🚀 From Migrations to Production: Generating SQL Scripts the Right Way
By Mohammed Rehan Javed Abdul Karim | Cloud Data Platform Engineer | Capgemini
Deploying database changes to production is a high-stakes operation. Whether you're working in a microservices architecture or managing a monolithic application, schema evolution must be handled with precision. One of the safest and most auditable ways to apply changes is by generating SQL scripts from ORM migrations—especially when using Entity Framework Core (EF Core).
In this article, I’ll walk you through how to generate SQL scripts from EF Core migrations, why it’s the preferred method for production deployments, and how to integrate it into your CI/CD pipeline.
🧠 Why SQL Scripts Over Direct Migration?
While EF Core allows you to apply migrations directly using dotnet ef database update, this approach is not recommended for production. Here's why:
🛠️ Step-by-Step: Generating SQL Scripts from EF Core Migrations
1. Basic Script Generation
To generate a SQL script for all migrations:
dotnet ef migrations script
This creates a script from the initial state to the latest migration.
2. Script Between Specific Migrations
dotnet ef migrations script FromMigration ToMigration
Example:
dotnet ef migrations script InitialMigration AddAuditTable
This is useful for incremental deployments.
3. Idempotent Scripts for Multi-Environment Safety
dotnet ef migrations script --idempotent
This script checks which migrations have already been applied and only applies the missing ones—perfect for distributed or multi-tenant environments.
📦 Bonus: Migration Bundles (EF Core 6+)
EF Core now supports migration bundles, which compile migrations into a standalone executable:
dotnet ef migrations bundle --self-contained --target-runtime win-x64
.\efbundle.exe --connection "YourConnectionString"
This is ideal for environments where the .NET SDK isn’t installed.
🧪 Best Practices for Production Deployment
📣 Tags & Mentions
To boost visibility and connect with the right audience, here are some relevant hashtags and mentions:
🔖 Hashtags:
#EFCore #SQLScripts #DevOps #CloudEngineering #DotNet #EntityFramework #DatabaseMigration #CI_CD #SoftwareArchitecture #ProductionReady #CapgeminiTech #TechLeadership #DataPlatform #LinkedInLearning
👥 Mentions:
💬 Final Thoughts
Generating SQL scripts from migrations is more than just a technical step—it’s a strategic move toward safer, scalable, and maintainable deployments. Whether you're a Cloud Engineer, DevOps Specialist, or Software Architect, mastering this process is essential for modern development workflows.
Have you used SQL scripts in your production deployments? Share your experience or drop your questions below 👇