Cum să încarci date în tabele cu Liquibase
DodaTech
Updated 2025-01-15
1 min read
In this tutorial, you'll learn about Cum să încarci date în tabele cu Liquibase. We cover key concepts, practical examples, and best practices.
Liquibase oferă loadData și loadUpdateData pentru încărcarea datelor din fișiere CSV direct în tabele, util pentru date de referință sau seed.
Problema
Ai nevoie să populezi tabele cu date inițiale (țări, statusuri, roluri) într-un mod versionat și reproductibil.
Pregătirea fișierului CSV
users.csv:
id,name,email
1,Ion Popescu,ion@example.com
2,Ana Maria,ana@example.com
3,Radu Ionescu,radu@example.com
Încărcarea datelor
În XML:
<changeSet id="load-users" author="ionut">
<loadData tableName="users" file="data/users.csv" relativeToChangelogFile="true"/>
</changeSet>
În YAML:
- changeSet:
id: load-users
author: ionut
changes:
- loadData:
tableName: users
file: data/users.csv
relativeToChangelogFile: true
Maparea coloanelor
- loadData:
tableName: users
file: data/users.csv
relativeToChangelogFile: true
columns:
- column:
name: id
type: NUMERIC
- column:
name: name
type: STRING
- column:
name: email
type: STRING
LoadUpdateData (upsert)
- changeSet:
id: load-or-update-users
author: ionut
changes:
- loadUpdateData:
tableName: users
file: data/users.csv
primaryKey: id
Erori frecvente
- Cale CSV greșită — fișierul trebuie să existe la calea specificată.
- Header lipsă — CSV-ul trebuie să aibă antet cu numele coloanelor.
- Tip incorect — valorile trebuie să corespundă tipurilor coloanelor.
- Separator greșit — Liquibase așteaptă separator implicit virgulă.
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