Tool for creating database migration scripts to be used by Liquibase.
Killer (and main) feature: Change datatype of primary key column(s) using Liquibase. Changing datatype of column(s) used as PK is a rather complex procedure which involves following steps (may be DB-specific):
- temporarily drop PK (otherwise column can not be changed coz it is used in PK index)
- modify PK column datatype
- restore PK
When foreign keys (FK) in other tables (referencing modified column) exist the things go even more complicated, involving following steps:
- temporarily drop FK(s) in dependent tables (otherwise PK can not be dropped)
- temporarily drop PK
- modify PK column datatype
- modify all FK column(s) datatype
- restore PK
- restore FK(s)
The "changegen" tool automates all listed steps. You need to provide just table name, column name and new datatype - the tool will generate all Liquibase statements for droping & restoring PK and FKs (if exist). Internally changegen connects to database (readonly) and uses INFORMATION_SCHEMA to obtain all information about column relations.
Currently only MSSQL and H2 DBs are supported. To support other DBs just add dependency to required JDBC driver.
- Copy src/main/resources/datasource.properties.example to src/main/resources/datasource.properties and modify DB connection configs
- Modify table name, column name and datatype in main() method of Main class
- Launch Main class
- Changesets for Liquibase will be generated and dumped to console
Note: mind cases of table & column names, tool relies on JDBC functionality which is case-sensitive (need to fix?)
- create CLI launcher
- output a well-formed <changeSet/> instead of just simple DDL statements
- add more JDBC drivers
- (?) split changes into different changesets for DBs that doesn't support transactional DDL modifications