<?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="poll_option-table">
        <createTable tableName="poll_option">
            <column name="id" autoIncrement="true" type="BIGINT">
                <constraints nullable="false"/>
            </column>
            <column name="poll_id" type="BIGINT">
                <constraints nullable="false"/>
            </column>
            <column name="created" type="TIMESTAMP WITHOUT TIME ZONE">
                <constraints nullable="false"/>
            </column>
            <column name="updated" type="TIMESTAMP WITHOUT TIME ZONE"/>
            <column name="server_id" type="BIGINT">
                <constraints nullable="false"/>
            </column>
            <column name="label" type="VARCHAR(100)">
                <constraints nullable="false"/>
            </column>
            <column name="value" type="VARCHAR(100)">
                <constraints nullable="false"/>
            </column>
            <column name="description" type="VARCHAR(100)">
                <constraints nullable="false"/>
            </column>
            <column name="adder_user_in_server_id" type="BIGINT">
                <constraints nullable="true"/>
            </column>
        </createTable>
        <addPrimaryKey columnNames="id" tableName="poll_option" constraintName="pk_poll_option" validate="true"/>
        <addForeignKeyConstraint baseColumnNames="adder_user_in_server_id" baseTableName="poll_option" constraintName="fk_poll_option_adder"
                                 deferrable="false" initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION"
                                 referencedColumnNames="user_in_server_id" referencedTableName="user_in_server" validate="true"/>
        <addForeignKeyConstraint baseColumnNames="server_id" baseTableName="poll_option" constraintName="fk_poll_option_server"
                                 deferrable="false" initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION"
                                 referencedColumnNames="id" referencedTableName="server" validate="true"/>
        <addForeignKeyConstraint baseColumnNames="poll_id" baseTableName="poll_option" constraintName="fk_poll_option_poll"
                                 deferrable="false" initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION"
                                 referencedColumnNames="id" referencedTableName="poll" validate="true"/>
        <sql>
            DROP TRIGGER IF EXISTS poll_option_update_trigger ON poll_option;
            CREATE TRIGGER poll_option_update_trigger BEFORE UPDATE ON poll_option FOR EACH ROW EXECUTE PROCEDURE update_trigger_procedure();
        </sql>
        <sql>
            DROP TRIGGER IF EXISTS poll_option_insert_trigger ON poll_option;
            CREATE TRIGGER poll_option_insert_trigger BEFORE INSERT ON poll_option FOR EACH ROW EXECUTE PROCEDURE insert_trigger_procedure();
        </sql>
    </changeSet>
</databaseChangeLog>