Sobes.tech
Middle

Kāda ir jūsu pieredze ar Liquibase?

sobes.tech AI

Atbilde no AI

Pieredze darbā ar Liquibase ietver:

  • Datubāzes shēmas versiju pārvaldība: Izmantojot changelog failus (XML, YAML, JSON) DDL un DML skriptiem.
  • Migrāciju automatizācija: Liquibase integrācija CI/CD pipeline'os, lai automātiski piemērotu shēmas izmaiņas izlaišanas laikā.
  • Darbs ar dažādām datubāzēm: Pieredze ar Liquibase izmantošanu ar PostgreSQL, MySQL un Oracle.
  • Rollback'i: Atgriešanas skriptu izveide un testēšana (rollback vai tag).
  • Komandrindas izmantošana: migrāciju veikšana, changelog failu ģenerēšana un statusa pārbaude.

Piemērs changelog faila struktūrai:

<!-- /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-4.0.xsd">

    <include file="changeset/create_users_table.xml" relativeToChangelogFile="true"/>
    <include file="changeset/add_index_to_users_table.xml" relativeToChangelogFile="true"/>

</databaseChangeLog>

Piemērs changeset:

<!-- /changeset/create_users_table.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-4.0.xsd">

    <changeSet id="create-users-table" author="devops-engineer">
        <createTable tableName="users">
            <column name="id" type="INT">
                <constraints primaryKey="true" nullable="false"/>
            </column>
            <column name="username" type="VARCHAR(50)">
                <constraints nullable="false" unique="true"/>
            </column>
            <column name="created_at" type="TIMESTAMP WITHOUT TIME ZONE" defaultValueComputed="CURRENT_TIMESTAMP"/>
        </createTable>
        <rollback>
            <dropTable tableName="users"/>
        </rollback>
    </changeSet>

</databaseChangeLog>

Komandrindas izmantošana:

# Visu izmaiņu piemērošana
liquibase update

# Skripta ģenerēšana manuālai lietošanai
liquibase updateSQL > update.sql

# Atgriezties līdz noteiktai zīmei
liquibase rollback <tag_name>

# Izmaiņu statusa rādīšana
liquibase status

Darbs ar tabulām un testdatiem, izmantojot loadData.

Tipiski Liquibase lietošanas scenāriji:

  • Jaunu programmu versiju izvietošana.
  • Kļūdu labošana datubāzē.
  • Testa vidi izveide.

Galvenās Liquibase priekšrocības:

  • Datubāzes shēmas versiju kontrole.
  • Neatkarība no konkrētas SGBD.
  • Izmaiņu atcelšanas iespēja.
  • Viegla integrācija ar CI/CD.