Main Options for Database DevOps
I’ve recently started a new contract that have goal to get their database structure into Git. This is laudable!👏 (you have your code in Git, right?!?)
At Omnitech we have a long running Teams chat going on the difference between State and Migration based versioning of Databases (we are MS SQL centric thinkers). I’ve compiled the feedback and created 2 small demos for my own learning to share with you.
State Based
- Visual Studio SQL Server Data Tools (SSDT) Database Projects
- Make all changes in Visual Studio and check in the changes
- Provides refactoring, validation at development time and Schema Management
- Multiple profiles for different options
- Can target specific SQL versions
- Works with Azure Databases
- Referenced databased can be worked around
- Works with Git and Pipelines for CI/CD
- .dacpac files are created via MSBuild that can be applied to databases
- May run into interesting deployment and development issues
- Sometimes it has required adhoc SQL for breaking schema changes to get the project back to valid for small teams. This could likely be avoided with more work where Audit compliance is more stringent
- One experienced enough “pain” that he wouldn’t recommend this approach again (for larger products he would use migrations)
- A more familiar approach for Developers
- Good for simple single database maintained by Developers
- You can see the full picture of what the database will be after changes are applied
- Free!
-
https://learn.microsoft.com/en-us/sql/tools/sql-database-projects/sql-database-projects?view=sql-server-ver16
Migration Based
- Use DBUp
- Transitions, not States
- More control than SQL Database Projects, you dictate and can see how the scripts are applied in order
- May need to look through migrations to determine what the final state will be
- A more familiar approach for DBAs of creating migration scripts
- Works with Git and Pipelines for CI/CD
- Create and Update scripts with a comparison tool or manually
- Add the script to Git with the correct name and folder
- In the pipeline, execute the DBUp runner applies each script in succession
- Free!
-
https://dbup.readthedocs.io/en/latest/philosophy-behind-dbup/
Another option is to use
Entity Framework Core with Migrations
.
Here is a good video explaining the process
.
RedGate Flyway
- You choose migration or state approach
- You can see the schema model and get migration scripts at the same time
- Created to help DBAs do DevOps
- Has a yearly per user cost
- Works with Git and pipelines
- A lot of helpful features are included
-
https://www.red-gate.com/products/flyway/
Which will you chose for your project?