Cum să creezi tabele cu Liquibase
DodaTech
Updated 2025-01-15
1 min read
In this tutorial, you'll learn about Cum să creezi tabele cu Liquibase. We cover key concepts, practical examples, and best practices.
Comanda createTable din Liquibase creează o tabelă nouă în baza de date, cu coloane, tipuri și constrângeri.
Problema
Trebuie să adaugi o tabelă nouă în schema bazei de date folosind Liquibase, asigurând versionarea și posibilitatea de rollback.
Crearea unei tabele
În XML:
<changeSet id="1" author="ionut">
<createTable tableName="users">
<column name="id" type="int" autoIncrement="true">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="name" type="varchar(255)">
<constraints nullable="false"/>
</column>
<column name="email" type="varchar(255)">
<constraints unique="true"/>
</column>
<column name="created_at" type="timestamp">
<constraints nullable="false"/>
</column>
</createTable>
<rollback>
<dropTable tableName="users"/>
</rollback>
</changeSet>
În YAML:
- changeSet:
id: 1
author: ionut
changes:
- createTable:
tableName: users
columns:
- column:
name: id
type: int
autoIncrement: true
constraints:
primaryKey: true
nullable: false
- column:
name: name
type: varchar(255)
rollback:
- dropTable:
tableName: users
Tipuri de coloane suportate
int,bigint,smallintvarchar(length),char(length)boolean,timestamp,datedecimal(precision, scale),floatclob,blob
Erori frecvente
- TableName lipsă — atributul
tableNameeste obligatoriu. - Tip incorect — tipul coloanei trebuie să fie suportat de baza de date.
- Constrângere duplicat — nu poți avea două chei primare pe aceeași tabelă.
- Rollback lipsă — fără rollback, tabela nu poate fi ștearsă automat.
FAQ
Built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro. DodaTech tools integrate seamlessly with Liquibase for enhanced productivity and security.
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro