database:liquibase
This is an old revision of the document!
Table of Contents
Liquibase
Tool to track B changes
TO clean up the checksum after the change do
update databasechangelog set md5sum = null where filename = '2014_10_27.xml';
how it works
Liquibase stores all metadata in 2 tables:
CREATE TABLE PUBLIC.DATABASECHANGELOGLOCK ... CREATE TABLE PUBLIC.DATABASECHANGELOG ...
Syntax of the call
- There is the syntax of the liquibase call.
- The Driver name: org.h2.Driver
- THe location of the Driver is: c:\doj\materials\Liquibase\h2jar\h2-1.4.197.jar
liquibase --driver=org.h2.Driver --classpath="c:\doj\materials\Liquibase\h2jar\h2-1.4.197.jar" --changeLogFile=../changelogs/extend.user.changelog.liquibase.xml --url="jdbc:h2:tcp://localhost:9092/mem:dbname" --username=mydbuser --password=mydbpass migrate
Example changeset
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
logicalFilePath="db-init-changelog"
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd" >
<changeSet author="alf" id="add-nickname-to-users" logicalFilePath="add-nickname-to-users">
<addColumn tableName="User">
<column name="nickname" type="varchar(8)"/>
</addColumn>
</changeSet>
<changeSet author="alf" id="sqlfile-usernames-add-nicknames" logicalFilePath="sqlfile-usernames-add-nicknames">
<sqlFile dbms="h2, oracle"
encoding="utf8"
endDelimiter="\nGO"
path="extend.user.changelog.liquibase.sql"
relativeToChangelogFile="true"
splitStatements="true"
stripComments="true"/>
</changeSet>
</databaseChangeLog>
logicalFilePath
To avoid the repetition of already executed changeSets - explicitely set the logicalFilePath on the databaseChangeLog and every chagneSet.
The table tracks each changeSet as a row, identified by a combination of the “id”, “author” and a “filename” column which stores the path to the changelog file.
Please note that the filename column stores the path to the changelog. This may be an absolute path or a relative path depending on how the changelog was passed to Liquibase. For best results, it should be a relative path.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<databaseChangeLog logicalFilePath="does-not-matter" xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-2.0.xsd">
<changeSet logicalFilePath="path-independent" author="authorId" id="1">
...
</changeSet>
</databaseChangeLog>
https://www.liquibase.org/documentation/databasechangelog.html
Debug
# create a tunnel to the STAGE ssh jump server and the postgres db on STAGE sudo ssh -i /home/vagrant/.ssh/ssh.openssh.priv -NL 9000:privatedbdns.com:5432 myuser@11.222.33.111 -v # connect the postgres database psql -h localhost -p 9000 -U MyAdmin --dbname my_db # PSQL password: thepassword # list schemas select schema_name from information_schema.schemata; # list tables \dt *.* # show the liquibase history SELECT * FROM databasechangelog; # remove the liquibase history DELETE FROM databasechangelog; # MANUAL creation of the schema. DONT DO THAT CREATE SCHEMA my_db; # MANUAL REMOVAL of the schema. DONT DO THAT!!!!!!!!!!!!!!!!!!! DROP SCHEMA my_db CASCADE;
database/liquibase.1562682113.txt.gz · Last modified: (external edit)
