database:liquibase
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| database:liquibase [2018/04/27 10:28] – skipidar | database:liquibase [2023/11/01 07:13] (current) – ↷ Page moved from business_process_management:camunda:database:liquibase to database:liquibase skipidar | ||
|---|---|---|---|
| Line 8: | Line 8: | ||
| </ | </ | ||
| + | === how it works=== | ||
| + | Liquibase stores all metadata in 2 tables: | ||
| + | < | ||
| + | CREATE TABLE PUBLIC.DATABASECHANGELOGLOCK ... | ||
| + | CREATE TABLE PUBLIC.DATABASECHANGELOG ... | ||
| + | </ | ||
| + | |||
| + | |||
| + | ===Syntax of the call=== | ||
| + | |||
| + | == H2 == | ||
| - | ==Syntax of the call== | ||
| * There is the syntax of the liquibase call. | * There is the syntax of the liquibase call. | ||
| * The Driver name: org.h2.Driver | * The Driver name: org.h2.Driver | ||
| Line 16: | Line 26: | ||
| liquibase --driver=org.h2.Driver --classpath=" | liquibase --driver=org.h2.Driver --classpath=" | ||
| </ | </ | ||
| + | |||
| + | == Postgres == | ||
| + | < | ||
| + | wget -O liquibase.tar.gz https:// | ||
| + | tar -xzvf liquibase.tar.gz | ||
| + | |||
| + | |||
| + | |||
| + | wget -O postgresql-jdbc4.jar https:// | ||
| + | |||
| + | chmod +x postgresql-jdbc4.jar | ||
| + | |||
| + | ./liquibase --driver=org.postgresql.Driver --classpath="/ | ||
| + | </ | ||
| + | |||
| + | |||
| + | |||
| + | == Example changeset== | ||
| + | < | ||
| + | <?xml version=" | ||
| + | |||
| + | < | ||
| + | logicalFilePath=" | ||
| + | xmlns=" | ||
| + | xmlns: | ||
| + | xmlns: | ||
| + | xsi: | ||
| + | http:// | ||
| + | |||
| + | < | ||
| + | < | ||
| + | <column name=" | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | < | ||
| + | <sqlFile dbms=" | ||
| + | encoding=" | ||
| + | endDelimiter=" | ||
| + | path=" | ||
| + | relativeToChangelogFile=" | ||
| + | splitStatements=" | ||
| + | stripComments=" | ||
| + | </ | ||
| + | |||
| + | </ | ||
| + | </ | ||
| + | |||
| + | |||
| + | |||
| + | == 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=" | ||
| + | < | ||
| + | xmlns: | ||
| + | xsi: | ||
| + | |||
| + | < | ||
| + | ... | ||
| + | </ | ||
| + | |||
| + | </ | ||
| + | |||
| + | https:// | ||
| + | </ | ||
| + | |||
| + | |||
| + | == Debug == | ||
| + | < | ||
| + | # create a tunnel to the STAGE ssh jump server and the postgres db on STAGE | ||
| + | sudo ssh -i / | ||
| + | |||
| + | # 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; | ||
| + | |||
| + | </ | ||
| + | |||
| + | |||
| + | |||
| + | === With Spring Boot === | ||
| + | |||
| + | |||
| + | == INit the DB at start == | ||
| + | |||
| + | To init the table - you only need the core **org.liquibase: | ||
| + | |||
| + | build.gradle | ||
| + | <sxh perl> | ||
| + | dependencies { | ||
| + | // liquibase | ||
| + | compile ' | ||
| + | |||
| + | // get the to the classpath which is needed but not loaded with " | ||
| + | compile group: ' | ||
| + | |||
| + | } | ||
| + | </ | ||
| + | |||
| + | |||
| + | application.properties | ||
| + | <sxh perl> | ||
| + | # https:// | ||
| + | spring.datasource.driver-class-name=org.postgresql.Driver | ||
| + | spring.datasource.username=postgres | ||
| + | spring.datasource.password=postgres | ||
| + | spring.datasource.host=localhost | ||
| + | spring.datasource.port=5432 | ||
| + | spring.datasource.database=postgres | ||
| + | spring.datasource.url=jdbc: | ||
| + | |||
| + | |||
| + | |||
| + | # Liquibase without prefix | ||
| + | # | ||
| + | spring.liquibase.enabled=true | ||
| + | spring.liquibase.change-log=classpath:/ | ||
| + | spring.liquibase.default-schema=public | ||
| + | spring.liquibase.user=postgres | ||
| + | spring.liquibase.password=postgres | ||
| + | |||
| + | # will be taken from spring.* | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | </ | ||
| + | |||
| + | resources/ | ||
| + | < | ||
| + | databaseChangeLog: | ||
| + | - includeAll: | ||
| + | path: db/ | ||
| + | </ | ||
| + | |||
| + | resources/ | ||
| + | < | ||
| + | <?xml version=" | ||
| + | < | ||
| + | < | ||
| + | < | ||
| + | <column name=" | ||
| + | < | ||
| + | </ | ||
| + | </ | ||
| + | </ | ||
| + | | ||
| + | ... | ||
| + | </ | ||
| + | |||
| + | |||
database/liquibase.1524824926.txt.gz · Last modified: (external edit)
