Hello Liquibase forum, hope you are well.
Have some newbie user questions for you all
Goal:
- Use liquibase latest docker image with h2 in a simple gitlab ci pipeline testing a couple changesets, tags for each, and a rollback to the first changeset’s tag.
Things I have tried:
liquibase init start-h2
- fails due to browser trying to open, does not seem to honor the settings to keep browser from opening… but will honor other settings (tried with env vars, cli, properties, etc), gets stuck waiting for the browser to open till pipeline times out (1hr).
- detached mode fails due to java error when trying to open the webpage
- H2 manual start got further:
nohup java -cp /liquibase/internal/lib/h2.jar org.h2.tools.Server -ifNotExists -webDaemon -tcpDaemon -tcpPort 9090 &
- This works, able to connect and run changesets, though they are “stuck” in pending
4 changesets have not been applied to DBUSER@jdbc:h2:tcp://localhost:9090/mem:dev
Here is the configuration:
- liquibase.properties:
--project-dir=./
--changelog-file=test/changelog.xml
--project-defaults-file=liquibase.properties
--url=jdbc:h2:tcp://localhost:9090/mem:dev
--username=dbuser
--password=letmein
--liquibase.command.init.startH2.launchBrowser=false
--liquibase.command.launchBrowser=false
- test/changelog.xml:
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd
http://www.liquibase.org/xml/ns/pro
http://www.liquibase.org/xml/ns/pro/liquibase-pro-latest.xsd
http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd">
<changeSet id="1" author="anakin.skywalker" labels="change1">
<createTable tableName="testTable">
<column name="id" type="int" autoIncrement="true">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="testColumn" type="varchar(50)">
<constraints nullable="false"/>
</column>
<column name="active" type="boolean" defaultValueBoolean="true"/>
</createTable>
</changeSet>
<changeSet id="1.1" author="anakin.skywalker" labels="change1">
<tagDatabase tag="TAG_1"/>
</changeSet>
<changeSet id="2" author="luke.skywalker" labels="change2">
<createTable tableName="company">
<column name="address" type="varchar(255)"/>
</createTable>
</changeSet>
<changeSet id="2.1" author="luke.skywalker" labels="change2">
<tagDatabase tag="TAG_2"/>
</changeSet>
</databaseChangeLog>
- .gitlab-yml (runs the whole dealio)
.functions: &functions |
function isUpToDate(){
status=$(liquibase status --verbose)
if [[ $status == *'is up to date'* ]]; then
echo "database is already up to date" & exit 0
fi;
}
function isRollback(){
if [ -z "$TAG" ]; then
echo "No TAG provided, running any pending changes"
elif [[ "$(liquibase tag-exists --tag=$TAG)" ]]; then
liquibase --logLevel=info --logFile=${CI_JOB_NAME}_${CI_PIPELINE_ID}.log rollback --tag=$TAG && exit 0
else exit 0
fi;
}
.liquibase-job:
stage: build
image: docker.artifactory.bbtnet.com/liquibase:latest
tags:
- $RUNNER_TAG
script:
- *functions
- isRollback
- isUpToDate
- liquibase checks run
- liquibase update --label-filter=change1 --show-summary=VERBOSE
- liquibase update --label-filter=change2 --show-summary=VERBOSE
- liquibase update --show-summary=VERBOSE
- liquibase history
- export TAG="TAG_1"
- liquibase status --verbose
- liquibase unexpected-changesets --verbose
- isRollback
- liquibase history
variables:
LIQUIBASE_COMMAND_INIT_PROJECT_FORMAT: "xml"
liquibase-job:
extends: .liquibase-job
before_script:
- liquibase --version
- nohup java -cp /liquibase/internal/lib/h2.jar org.h2.tools.Server -ifNotExists -webDaemon -tcpDaemon -tcpPort 9090 &
Any ideas on what I’m doing wrong?
Or what would be an easier way to do what we are trying to do?
Found only a couple posts on the web concerning this usage, much less on the uncommitted/pending changesets for the H2 database.
Thank you for your time and effort in this!