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

    <!--
        Added the entity DashboardComponentOrganization.
    -->
    <changeSet id="20250502222301-1" author="omg">
        <createTable tableName="dashboard_component_org" remarks="DashboardComponentOrganization">
            <column name="id" type="bigint" autoIncrement="true" startWith="1">
                <constraints primaryKey="true" nullable="false"/>
            </column>
            <column name="dashboard_component_id" type="bigint" remarks="Parent DashboardComponent">
                <constraints nullable="false" />
            </column>
            <column name="organization_id" type="bigint" remarks="Relation with Organization">
                <constraints nullable="false" />
            </column>
            <column name="version" type="integer" defaultValueNumeric="-1" remarks="Record version for concurrency control.">
                <constraints nullable="false" />
            </column>
        </createTable>
    </changeSet>

	<changeSet id="20250502222301-2" author="omg">
        <addForeignKeyConstraint baseColumnNames="dashboard_component_id"
                                 baseTableName="dashboard_component_org"
                                 constraintName="fk_dashboard_component_org__dashboard_component_id"
                                 referencedColumnNames="id"
                                 referencedTableName="dashboard_component"
                                 />
                                 
        <addForeignKeyConstraint baseColumnNames="organization_id"
                                 baseTableName="dashboard_component_org"
                                 constraintName="fk_dashboard_component_org__organization_id"
                                 referencedColumnNames="id"
                                 referencedTableName="organization"
                                 />
    </changeSet>        
</databaseChangeLog>
