<?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">

    <!--
        Altered the entity DashboardComponentDetail.
        #1 Add relation column to parent dashboard_component_id
    -->
    <changeSet id="20250215093000-1" author="jhipster">
    	<!-- Step 1: Add the column to the existing table -->
    	<addColumn tableName="dashboard_component_detail">
	        <column name="dashboard_component_id" type="bigint">
	        	<constraints nullable="false" />
	        </column>
	    </addColumn>
	    
	    <!-- Step 2: Add foreign key constraint to link it with the referenced table -->
	    <addForeignKeyConstraint
	        baseTableName="dashboard_component_detail"
	        baseColumnNames="dashboard_component_id"
	        referencedTableName="dashboard_component"
	        referencedColumnNames="id"
	        constraintName="fk_dashboard_component_detail__dashboard_component_id"/>
    </changeSet>

    <!--
        Altered the entity DashboardComponentDetail.
        #2 Change column variable_id to a relation FK
    -->
    <changeSet id="20250215093000-2" author="jhipster">
    	<!-- Step 1: Add the column to the existing table -->
    	<modifyDataType tableName="dashboard_component_detail" columnName="variable_id" newDataType="bigint" />
	    
	    <!-- Step 2: Add foreign key constraint to link it with the referenced table -->
	    <addForeignKeyConstraint
	        baseTableName="dashboard_component_detail"
	        baseColumnNames="variable_id"
	        referencedTableName="variable"
	        referencedColumnNames="id"
	        constraintName="fk_dashboard_component_detail__variable_id"/>
    </changeSet>
</databaseChangeLog>
