How to automate database deployment with Liquibase?

The translation of the material was prepared as part of the course "Express Course on Migration Management (DBVC)".






Liquibase — . , SQL ( XML) . , git.





, Liquibase.





1. Jenkins 





2. Shell-





, — , .





Liquibase, .. XML SQL. SQL, XML SQL. , SQL-, , Liquibase.





, Postgre, . , Liquibase .





:





changelog ( )

XML- liquibase-changelog.xml ( !) :





<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog 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-3.1.xsd">
<include file="<path to changeset SQL file>/<changeset file name>.sql>" relativeToChangelogFile="true"/>
...more <include> tags goes here...
</databaseChangeLog>
      
      



include



XML. SQL changeset ( ), Liquibase, changelog ( ).





(changeset) SQL

SQL changeset . SQL, Liquibase, :





--liquibase formatted sql
--changeset <author name>:<a unique identifier for the SQL changeset>
<SQL statements go here>
<SQL statements go here>
--rollback <rollback SQL statements>
--rollback <rollback SQL statements>
      
      



:





--liquibase formatted sql
--changeset xameeramir:create-test-table
CREATE TABLE IF NOT EXISTS testTable(
columnName1 VARCHAR (355)
);
--rollback DROP TABLE
--rollback testTable
      
      



, SQL changeset XML changelog.





SQL changeset XML- changelog 

SQL changeset changelog, , XML:





<include file=”<path to SQL changeset file>/<changeset file name>.sql” relativeToChangelogFile="true" />
      
      



SQL changesets changelog, .





Liquibase

:





liquibase --changeLogFile=<path to changelog file>/<liquibase changelog file name>.xml --username=<database username> --password=<database password> --classpath=<path to the liquibase installation>/postgresql-42.2.5.jar --url=jdbc:postgresql://<database url>/<database name> update
      
      



Classpath ( ) - JDBC, . Postgresql-42.2.5.jar - JDBC-, Postgres, - .





shell- CI/CD .





CI/CD

, - shell-, shell- CI/CD.





, CI/CD, Liquibase, (trigger) Liquibase, , git push DEVELOP ( ).





liquibase-changelog.xml. , ~/ include, , changeset SQL. CI/CD:





  • SQL changeset .





  • DEVELOP





  • feature DEVELOP.





  • CI/CD, DEVELOP, Liquibase .





  • Liquibase ( ).





shell-

shell- Liquibase. shell- , changeset ( ) Liquibase .





, shell- , ? :





  • Shell- cron.





  • Shell- .





!






- (DBVC)








All Articles