<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
                     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                     xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.26.xsd" >
    <changeSet author="Sheldan" id="stream_session_section-table">
        <createTable tableName="stream_session_section">
            <column name="id" type="BIGINT" autoIncrement="true">
                <constraints nullable="false" primaryKey="true"/>
            </column>
            <column name="stream_session_id" type="BIGINT">
                <constraints nullable="false"/>
            </column>
            <column name="streamer_id" type="BIGINT">
                <constraints nullable="false"/>
            </column>
            <column name="game_id" type="VARCHAR(255)">
                <constraints nullable="false"/>
            </column>
            <column name="game_name" type="VARCHAR(255)">
                <constraints nullable="false"/>
            </column>
            <column name="viewer_count" type="INT">
                <constraints nullable="false"/>
            </column>
            <column name="title" type="VARCHAR(255)">
                <constraints nullable="false"/>
            </column>
            <column name="created" type="TIMESTAMP WITHOUT TIME ZONE">
                <constraints nullable="false"/>
            </column>
            <column name="updated" type="TIMESTAMP WITHOUT TIME ZONE"/>

        </createTable>

        <addForeignKeyConstraint baseColumnNames="streamer_id" baseTableName="stream_session_section" constraintName="fk_stream_session_section_streamer"
                                 deferrable="false" initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION"
                                 referencedColumnNames="id" referencedTableName="streamer" validate="true"/>

        <addForeignKeyConstraint baseColumnNames="stream_session_id" baseTableName="stream_session_section" constraintName="fk_stream_session_section_session"
                                 deferrable="false" initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION"
                                 referencedColumnNames="id" referencedTableName="stream_session" validate="true"/>

        <sql>
            DROP TRIGGER IF EXISTS stream_session_section_update_trigger ON stream_session_section;
            CREATE TRIGGER stream_session_section_update_trigger BEFORE UPDATE ON stream_session_section FOR EACH ROW EXECUTE PROCEDURE update_trigger_procedure();
        </sql>
        <sql>
            DROP TRIGGER IF EXISTS stream_session_section_insert_trigger ON stream_session_section;
            CREATE TRIGGER stream_session_section_insert_trigger BEFORE INSERT ON stream_session_section FOR EACH ROW EXECUTE PROCEDURE insert_trigger_procedure();
        </sql>
    </changeSet>
</databaseChangeLog>