Scope
Currently we have Liquibase running db setup for CPS and NCMP with many steps
We want to
- condense the steps
- separate out the NCMP steps so that they can be run by a model loader instead.
Intended method
Currently we have 16 Liquibase change set files which we want to condense down to 1 or 2 files.
In order to save the database state I exported the current database to sql statements which can be used instead of the sequential liquibase steps. This was achieved using DBeaver export functionality.
For creating the tables we want to retain the first change set file 01-createCPSTables.yaml. However there is a constraint in this file which we can remove as it is removed in liquibase step 06. Therefore remove change set 1-21.
We can then add steps to add the sql exported data. This can be achieved with the following:
NB: There is an issue with this current implementation as an error is generated due to the foreign key constraints either existing too early or too late. The data insert may need to be separated around the foreign key constraints.
Checksum
This implementation also doesn't yet account for the checksum issues which will occur. Liquibase generates a checksum for every changeset which it enacts. If the checksum does not match for each step during start up /upgrade then an error will occur and it will fail.
The validCheckSum should solve this issue as we can define that the error checksum is valid. This should only need to be done on the first changeset of the new changesets. It should look something like this I think (The only examples I have seen are in XML and I'm not sure it translates 1-1 for YAML):
To get the actual checksum it is necessary to run a liquibase upgrade and get the checksum from the error message.
For more on valid check sum: https://www.liquibase.com/blog/what-affects-changeset-checksums