|
|
# Migrations
|
|
|
When an application is already deployed and changes to the database are necessary, a migration needs to be written. This can be done as follows. If you have never written a migration before, obtain `h2-1.3.176.jar` and `liquibase.zip` from another developer. Then add liquibase to your path. When this is done, run the development branch with the following settings:
|
|
|
```
|
|
|
spring:
|
|
|
jpa:
|
|
|
hibernate:
|
|
|
ddl-auto: create
|
|
|
datasource:
|
|
|
url: jdbc:h2:file:./testdb-old;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;DATABASE_TO_UPPER=false;
|
|
|
username: sa
|
|
|
password:
|
|
|
```
|
|
|
Then run your branch, but change `testdb-old` to `testdb-new`. Afterwards, you can generate a changelog with the following script:
|
|
|
```
|
|
|
PROJ_DIR=$1
|
|
|
RESOURCES_DIR=$PROJ_DIR/src/main/resources
|
|
|
|
|
|
liquibase \
|
|
|
--username=sa \
|
|
|
--password= \
|
|
|
--changeLogFile=$RESOURCES_DIR/changes.yaml \
|
|
|
--driver=org.h2.Driver \
|
|
|
--url=jdbc:h2:$PROJ_DIR/testdb-old \
|
|
|
--classpath=/usr/local/apps/h2/h2-1.3.176.jar \
|
|
|
--logLevel=info \
|
|
|
diffChangeLog \
|
|
|
--referenceUrl=jdbc:h2:$PROJ_DIR/testdb-new \
|
|
|
--referenceUsername=sa \
|
|
|
--referencePassword=
|
|
|
```
|
|
|
Finally, copy your changes from `changes.yaml` to the bottom of `migrations.yaml`. Double check whether the generated changelog makes sense. Sometimes, you might need to add default values or change column types.
|
|
|
|