<?xml version="1.0" encoding="utf-8" ?>
<database Name="otrs">
    <TableAlter Name="link_relation">
        <IndexCreate Name="link_relation_list_source">
            <IndexColumn Name="source_object_id"/>
            <IndexColumn Name="source_key"/>
            <IndexColumn Name="state_id"/>
        </IndexCreate>
        <IndexCreate Name="link_relation_list_target">
            <IndexColumn Name="target_object_id"/>
            <IndexColumn Name="target_key"/>
            <IndexColumn Name="state_id"/>
        </IndexCreate>
    </TableAlter>

    <!-- scheduler tables -->
    <Table Name="scheduler_task">
        <Column Name="id" Required="true" PrimaryKey="true" AutoIncrement="true" Type="BIGINT"/>
        <Column Name="ident" Required="true" Type="BIGINT"/>
        <Column Name="name" Required="false" Size="150" Type="VARCHAR"/>
        <Column Name="task_type" Required="true" Size="150" Type="VARCHAR"/>
        <Column Name="task_data" Required="true" Type="LONGBLOB"/>
        <Column Name="attempts" Required="true" Type="SMALLINT"/>
        <Column Name="lock_key" Required="true" Type="BIGINT"/>
        <Column Name="lock_time" Required="false" Type="DATE"/>
        <Column Name="lock_update_time" Required="false" Type="DATE"/>
        <Column Name="create_time" Required="true" Type="DATE"/>
        <Unique Name="scheduler_task_ident">
            <UniqueColumn Name="ident"/>
        </Unique>
        <Index Name="scheduler_task_ident_id">
            <IndexColumn Name="ident"/>
            <IndexColumn Name="id"/>
        </Index>
        <Index Name="scheduler_task_lock_key_id">
            <IndexColumn Name="lock_key"/>
            <IndexColumn Name="id"/>
        </Index>
    </Table>

    <Table Name="scheduler_future_task">
        <Column Name="id" Required="true" PrimaryKey="true" AutoIncrement="true" Type="BIGINT"/>
        <Column Name="ident" Required="true" Type="BIGINT"/>
        <Column Name="execution_time" Required="true" Type="DATE"/>
        <Column Name="name" Required="false" Size="150" Type="VARCHAR"/>
        <Column Name="task_type" Required="true" Size="150" Type="VARCHAR"/>
        <Column Name="task_data" Required="true" Type="LONGBLOB"/>
        <Column Name="attempts" Required="true" Type="SMALLINT"/>
        <Column Name="lock_key" Required="true" Type="BIGINT"/>
        <Column Name="lock_time" Required="false" Type="DATE"/>
        <Column Name="create_time" Required="true" Type="DATE"/>
        <Unique Name="scheduler_future_task_ident">
            <UniqueColumn Name="ident"/>
        </Unique>
        <Index Name="scheduler_future_task_ident_id">
            <IndexColumn Name="ident"/>
            <IndexColumn Name="id"/>
        </Index>
        <Index Name="scheduler_future_task_lock_key_id">
            <IndexColumn Name="lock_key"/>
            <IndexColumn Name="id"/>
        </Index>
    </Table>

    <Table Name="scheduler_recurrent_task">
        <Column Name="id" Required="true" PrimaryKey="true" AutoIncrement="true" Type="BIGINT"/>
        <Column Name="name" Required="true" Size="150" Type="VARCHAR"/>
        <Column Name="task_type" Required="true" Size="150" Type="VARCHAR"/>
        <Column Name="last_execution_time" Required="true" Type="DATE"/>
        <Column Name="last_worker_task_id" Required="fasle" Type="BIGINT"/>
        <Column Name="last_worker_status" Required="false" Type="SMALLINT"/>
        <Column Name="last_worker_running_time" Required="false" Type="INTEGER"/>
        <Column Name="lock_key" Required="true" Type="BIGINT"/>
        <Column Name="lock_time" Required="false" Type="DATE"/>
        <Column Name="create_time" Required="true" Type="DATE"/>
        <Column Name="change_time" Required="true" Type="DATE"/>
        <Unique Name="scheduler_recurrent_task_name_task_type">
            <UniqueColumn Name="name"/>
            <UniqueColumn Name="task_type"/>
        </Unique>
        <Index Name="scheduler_recurrent_task_task_type_name">
            <IndexColumn Name="task_type"/>
            <IndexColumn Name="name"/>
        </Index>
        <Index Name="scheduler_recurrent_task_lock_key_id">
            <IndexColumn Name="lock_key"/>
            <IndexColumn Name="id"/>
        </Index>
    </Table>

    <TableDrop Name="scheduler_task_list"/>

    <!-- remove column that is used nowhere -->
    <TableAlter Name="auto_response">
        <ColumnDrop Name="text2"/>
    </TableAlter>

    <!-- notification_event_message -->
    <TableCreate Name="notification_event_message">
        <Column Name="id" Required="true" PrimaryKey="true" AutoIncrement="true" Type="INTEGER"/>
        <Column Name="notification_id" Required="true" Type="INTEGER"/>
        <Column Name="subject" Required="true" Size="200" Type="VARCHAR"/>
        <Column Name="text" Required="true" Size="4000" Type="VARCHAR"/>
        <Column Name="content_type" Required="true" Size="250" Type="VARCHAR"/>
        <Column Name="language" Required="true" Size="60" Type="VARCHAR"/>
        <ForeignKey ForeignTable="notification_event">
            <Reference Foreign="id" Local="notification_id"/>
        </ForeignKey>
        <Index Name="notification_event_message_notification_id">
            <IndexColumn Name="notification_id"/>
        </Index>
        <Index Name="notification_event_message_language">
            <IndexColumn Name="language"/>
        </Index>
        <Unique Name="notification_event_message_notification_id_language">
            <UniqueColumn Name="notification_id"/>
            <UniqueColumn Name="language"/>
        </Unique>
    </TableCreate>

    <!-- cloud service config table -->
    <TableCreate Name="cloud_service_config">
        <Column Name="id" Required="true" PrimaryKey="true" AutoIncrement="true" Type="INTEGER"/>
        <Column Name="name" Required="true" Size="200" Type="VARCHAR"/>
        <Column Name="config" Required="true" Type="LONGBLOB"/>
        <Column Name="config_md5" Required="true" Size="32" Type="VARCHAR"/>
        <Column Name="valid_id" Required="true" Type="SMALLINT"/>
        <Column Name="create_time" Required="true" Type="DATE"/>
        <Column Name="create_by" Required="true" Type="INTEGER"/>
        <Column Name="change_time" Required="true" Type="DATE"/>
        <Column Name="change_by" Required="true" Type="INTEGER"/>
        <Unique Name="cloud_service_config_name">
            <UniqueColumn Name="name"/>
        </Unique>
        <Unique Name="cloud_service_config_config_md5">
            <UniqueColumn Name="config_md5"/>
        </Unique>
        <ForeignKey ForeignTable="valid">
            <Reference Local="valid_id" Foreign="id"/>
        </ForeignKey>
        <ForeignKey ForeignTable="users">
            <Reference Local="create_by" Foreign="id"/>
            <Reference Local="change_by" Foreign="id"/>
        </ForeignKey>
    </TableCreate>

</database>
