Liquibase for Developers
Liquibase for Developers
Listen to Nathan Voxland's breakdown of Liquibase's many perks and decide if it's the right database change management tool for you.
Join the DZone community and get the full member experience.Join For Free
MariaDB TX, proven in production and driven by the community, is a complete database solution for any and every enterprise — a modern database for modern applications.
Store Your Database Changes With Your Code
Your database schema is an integral part of your application, so store your changelog files alongside your application code. That will allow your existing version control system to ensure everything is kept in sync–whenever you commit your code your database changes will go with it and whenever anyone updates their code they will get the new database schema.
Branches are an integral part of developing code and your database changes need to flow along with them. Because Liquibase tracks each changeSet independently rather than relying on a single incrementing "database version", when you merge in a branch all the new changeSets will execute as expected, even if there were "later" changeSets already executed.
When you do run into merge issues, the simple text formats used for the changelog files can be easily merged with your favorite tools.
Author changeSets in Your Favorite Markup
Liquibase supports changelogs written in XML, YAML, JSON, and SQL. Use whatever is most readable to you.
Know That Your Changes Will Not Get Forgotten Down the Line
Liquibase tracks which changelog statements have run against each database, so once you create a changeSet you can be confident that it will be deployed through QA and production.
For best results, whenever you need a database change append, add a new changeSet to your local database and then run Liquibase update to apply it. This works better than making changes to your database directly and re-writing it as a changeSet because you are truly running the same update as everyone else.
Like SQL? Use SQL
XML-formatted changelogs have their advantages, but many DBAs still prefer good, old-fashioned SQL. If that is what you are most comfortable working with, Liquibase-formatted SQL gives you the standard changeSet tracking used in any changelog format, but lets you specify the exact SQL you want.
Easier Test Data Management
Normally, test data is stored in something like CSV files which are loaded into the database after it is built. The problem with this strategy is that any schema changes will usually break in your data load process, leading to hours of time spent figuring out what the test data was trying to expose and then adjusting the files to match the new schema.
Instead of loading the data into the final schema, build up your test data within your changelog file. Use loadData or standard SQL to load data into the schema as it is now, then as new schema changes are appended to the changelog, your test data will be migrated just like production data would be. This not only keeps you from having to continually update your CSV files, but also helps verify that existing data is handled correctly.
Use contexts and labels to mark which changeSets contain test data so they are not deployed to production.
Liquibase ships with several tools you can use to make sure changes are being applied correctly and that nobody is sneaking in changes out of process:
- The status and validate commands report on what changeSets have not yet been run and checks the changelog for errors.
- The diff command reports on differences between databases to ensure that two fully updated databases are truly identical
- The dbdoc command generates documentation on the current database structure and its changes over time
Enterprise Features With Datical
Beyond all the standard Liquibase functionality, Datical lets you:
- Package database schema changes alongside application code
- Simulate deployments to forecast potential errors
- Enforce enterprise database standards with customized business rules
- Know the deployment status of every schema in the database
- Integrate with popular DevOps tools
Opinions expressed by DZone contributors are their own.