Hi all, i am new to Liquibase
, I am learning addLookupTable
from Liquibase docs, my understanding of lookup table is, that all the repeated data in the primary table
will be put into a lookup table
and a foreign key
constraint will be created between both tables.
below is the changelog file I am using
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" xmlns:pro="http://www.liquibase.org/xml/ns/pro" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="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 http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd">
<changeSet author="wesome" id="1692599548266-1">
<createTable catalogName="studentdb" tableName="student">
<column autoIncrement="true" name="student_id" type="BIGINT">
<constraints nullable="false" primaryKey="true" />
</column>
<column name="student_name" type="VARCHAR(255)" />
<column defaultValueComputed="CURRENT_TIMESTAMP" name="current_date_time" type="datetime" />
</createTable>
</changeSet>
<changeSet author="wesome" id="1692701200879-2">
<insert catalogName="studentdb" tableName="student">
<column name="student_name" value="StudentA" />
<column name="current_date_time" valueDate="now()" />
</insert>
</changeSet>
<changeSet author="wesome" id="1692701200879-3">
<insert catalogName="studentdb" tableName="student">
<column name="student_name" value="StudentB" />
<column name="current_date_time" valueDate="now()" />
</insert>
</changeSet>
<changeSet author="wesome" id="1692701200879-4">
<addLookupTable constraintName="fk_student_name" existingColumnName="student_name" existingTableName="student" newColumnDataType="VARCHAR(255)" newColumnName="student_name_lookup" newTableCatalogName="studentDb" newTableName="student_lookup" newTableSchemaName="studentDb" />
</changeSet>
</databaseChangeLog>
liquibase.properties
changeLogFile=changelog.mysql.xml
liquibase.command.url:jdbc:mysql://localhost:3306/studentDb?createDatabaseIfNotExist=true&autoReconnect=true&useSSL=false&allowPublicKeyRetrieval=true
liquibase.command.username : root
liquibase.command.password : rootroot
but the above script creates a student table
and student_lookup table
with all unique values from the student table
, but there is no relation between them.
both the student table
and student_lookup
table have the same data, and the newly created student_lookup
table doesn’t have a primary
key as well.
what I am missing?