Skip to content

liquibase

Andre Winkler edited this page Mar 28, 2020 · 5 revisions

Liquibase

Liquibase verwaltet ein SQL Datenbankschema in einem XML Format. Ein typisches Beispiel:

<?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-2.0.xsd">
    <changeSet id="1" author="andrewinkler">
        <createTable tableName="PERSON">
            <column name="ID" type="bigint(20)" autoIncrement="true">
                <constraints primaryKey="true" nullable="false"/>
            </column>
            <column name="NAME" type="varchar(50)">
                <constraints nullable="false" unique="true"/>
            </column>
            <column name="FIRSTNAME" type="varchar(50)"/>
            <column name="AGE" type="bigint(3)"/>
        </createTable>
        <addUniqueConstraint columnNames="NAME,FIRSTNAME"
                             constraintName="UQ_NAMEFIRSTNAME"
                             tableName="PERSON"/>
        <createTable tableName="ADDRESS">
            <column name="ID" type="bigint(20)" autoIncrement="true">
                <constraints primaryKey="true" nullable="false"/>
            </column>
            <column name="STREET" type="varchar(50)">
                <constraints nullable="false" unique="true"/>
            </column>
            <column name="CITY" type="varchar(50)">
                <constraints nullable="false" unique="true"/>
            </column>
            <column name="PERSON" type="biging(20)">
                <constraints nullable="false" unique="false"/>
            </column>
        </createTable>
        <addForeignKeyConstraint baseColumnNames="PERSON"
                                 baseTableName="ADDRESS"
                                 constraintName="FK_PERSON"
                                 referencedColumnNames="ID"
                                 referencedTableName="PERSON"/>
    </changeSet>
</databaseChangeLog>

Die Idee dahinter:

  • Datenbank Unabhängigkeit.
  • Nachvollziehbarkeit von Schemaänderungen. Die XML Informationen landen in ein oder mehreren XML Dateien. Die ausgeführten Änderungsoperationen werden in einer separaten Datenbanktabelle gespeichert. Damit kann Liquibase bei Bedarf notwendige Änderungen, um einen gewissen Versionsstand zu erreichen, selbständig einspielen.
  • ...

Vor und Nachteile

Vorteile

Nachteile

Clone this wiki locally