Cum să creezi un changelog SQL în Liquibase
DodaTech
Updated 2025-01-15
1 min read
In this tutorial, you'll learn about Cum să creezi un changelog SQL în Liquibase. We cover key concepts, practical examples, and best practices.
Liquibase suportă changelog-uri în format SQL, permițând utilizarea directă a comenzilor SQL native fără abstracția XML/YAML.
Problema
Preferi să scrii SQL direct sau migrezi o bază de date existentă cu scripturi SQL. Liquibase poate folosi fișiere SQL ca changelog-uri.
Structura unui changelog SQL
-- liquibase formatted sql
-- changeset ionut:1
CREATE TABLE users (
id SERIAL PRIMARY KEY,
name VARCHAR(255) NOT NULL,
email VARCHAR(255) UNIQUE NOT NULL
);
-- rollback DROP TABLE users;
-- changeset ionut:2
ALTER TABLE users ADD COLUMN phone VARCHAR(20);
-- rollback ALTER TABLE users DROP COLUMN phone;
Adnotări suportate
-- changeset autor:id
-- rollback comanda
-- preconditions tip expression
-- context context_name
-- labels label_name
Includerea changelog-urilor SQL
<databaseChangeLog>
<include file="changelogs/init.sql" relativeToChangelogFile="true"/>
</databaseChangeLog>
sau în YAML:
databaseChangeLog:
- include:
file: changelogs/init.sql
relativeToChangelogFile: true
Erori frecvente
- Fără
-- liquibase formatted sql— prima linie este obligatorie. - Fără
-- rollback— rollback-ul automat nu funcționează fără comanda explicită. - Format greșit —
-- changesettrebuie să aibă formatulautor:id. - Separator lipsă — folosește
;sauGOpentru a separa instrucțiunile.
FAQ
Built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro. DodaTech tools integrate seamlessly with Liquibase for enhanced productivity and security.
← Previous
Cum să creezi un changelog JSON în Liquibase
Next →
Cum să creezi un changelog XML în Liquibase
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro