Data Migration with Java
This type of migration should only be used if the logic cannot be implemented in SQL as part of a Liquibase changelog. The Java migrations are significantly slower since they need to load and convert the data from the DBMS into Java objects, apply the changes, and then write the new data back to the database.
The changelog can be found in
src/main/java/config/migration/MigrationRegistry.java. To create a new change, you have to do the following:
Get the current time in the format
Create a new file in
MigrationEntry<formatted-time>.javacontaining a class extending
Implement the required methods in your class and follow the JavaDoc.
Add the class to the
migrationEntryMapattribute in the
MigrationRegistry.javatogether with the next Integer key inside the constructor.
All executed entries are saved in the table
migration_changelog. If you delete entries, they get executed again.
Test your changes locally first, and only commit changes you are confident that work.
Before deploying any database changes to a test server, ask for official permission from the project lead. If the changes don’t get approved, manual rollbacks can be necessary, which are avoidable.
If queries fail due to the authorization object being null, call SecurityUtils.setAuthorizationObject() beforehand to set a dummy object.