Use UUID and load data

Last updated: September 2, 2025

Liquibase uses Universally Unique Identifiers (UUID)s to define tables so they are more easily searchable.

How to use UUID and load data

1

Define a table

Results

  • Tables are created by Liquibase successfully (changesets 1 and 2)

  • Liquibase inserts the data into that table (project_objectives).

  • Liquibase also supports adding UUIDs to the database successfully.

<?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"
  xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
  xmlns:pro="http://www.liquibase.org/xml/ns/pro"
    xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
        http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd
        http://www.liquibase.org/xml/ns/dbchangelog-ext
        http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd
        http://www.liquibase.org/xml/ns/pro
        http://www.liquibase.org/xml/ns/pro/liquibase-pro-latest.xsd">
  <changeSet id="1" author="mike">
    <createTable tableName="project">
      <column name="id" type="uuid">
        <constraints primaryKey="true" nullable="false"/>
      </column>
    </createTable>
  </changeSet>
  <changeSet id="2" author="mike">
    <createTable tableName="project_objectives">
      <column name="objectives_id" type="uuid">
        <constraints nullable="false"/>
      </column>
      <column name="project_id" type="uuid">
        <constraints nullable="false"/>
      </column>
    </createTable>
    <addPrimaryKey columnNames="project_id, objectives_id" tableName="project_objectives"/>
  </changeSet>
  <changeSet id="2-data" author="mike" context="test">
    <loadData
				file="test-data/project_objectives.csv"
				separator=";"
				tableName="project_objectives">
      <column name="objectives_id" type="uuid"/>
      <column name="project_id" type="uuid"/>
    </loadData>
  </changeSet>
</databaseChangeLog>
2

Add a CSV for Liquibase to insert

Add a CSV for Liquibase to insert with the same name as the loadData file above. In this exmple, it is project_objectives.csv in the test-data folder:

CSV to insert
loading
3

Run liquibase update to create the table and insert the data.

Use UUID and load data - Liquibase