<?xml version="1.0" encoding="utf-8"?>
<databaseChangeLog
    xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
    xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    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">

    <!--
        Clear all data from VariableClass table
    -->
	<changeSet id="20241025234007-1" author="omg">
	  <delete tableName="variable_class"/>
	</changeSet>

    <!--
        Alter the entity VariableClass.
        Drop connection to Variable table
    -->
    <changeSet id="20241025234007-2" author="omg">
	    <!-- Step 1: Drop the foreign key constraint -->
	    <dropForeignKeyConstraint
	        baseTableName="variable_class"
	        constraintName="fk_variable_class__variable_id"/>
	
	    <!-- Step 2: Drop the column -->
	    <dropColumn tableName="variable_class" columnName="variable_id"/>
    </changeSet>

    <!--
        Alter the entity VariableClass.
        Connect to VariableClassType
    -->
    <changeSet id="20241025180907-3" author="omg">
   	  <addColumn tableName="variable_class">
	    <column name="variable_class_type_id" type="bigint">
          <constraints nullable="true" />
        </column>
	  </addColumn>
    </changeSet>
    
    <!--
        Make FK to the new parent : VariableClassType
    -->
    <changeSet id="20241025180907-4" author="omg">

        <addForeignKeyConstraint baseColumnNames="variable_class_type_id"
                                 baseTableName="variable_class"
                                 constraintName="fk_variable_class__variable_class_type_id"
                                 referencedColumnNames="id"
                                 referencedTableName="variable_class_type"
                                 />
    </changeSet>
</databaseChangeLog>
