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

	<property name="datetimeType" value="DATETIME"/>

    <!--
        Added the entity ResilientLog.
    -->
    <changeSet id="20252104104000-1" author="omg">
        <createTable tableName="resilient_log" remarks="Resilient Log message tabel\nThis is a generic log table, for multiple processes to save event messages (Info; Warn; Error) that occours. This allows for asynchronous message reading.">
            <column name="id" type="bigint" autoIncrement="true" startWith="1">
                <constraints primaryKey="true" nullable="false"/>
            </column>
            <column name="owner_id" type="bigint">
                <constraints nullable="false" />
            </column>
            <column name="level" type="varchar(15)" remarks="The level of the log. INFO; WARN; ERROR">
                <constraints nullable="false" />
            </column>
            <column name="log_message" type="varchar(255)" remarks="The log of the event.">
                <constraints nullable="false" />
            </column>
            <column name="creation_date" type="${datetimeType}" remarks="The creation date (insert). When the data was inserted into the system.">
                <constraints nullable="false" />
            </column>
            <column name="creation_username" type="varchar(255)" remarks="The actual username logged into the system, that inserted the data. NOT a reference to the user, but the login username.">
                <constraints nullable="false" />
            </column>
            <column name="version" type="integer" defaultValueNumeric="-1" remarks="Record version for concurrency control.">
                <constraints nullable="false" />
            </column>
        </createTable>
        <dropDefaultValue tableName="resilient_log" columnName="creation_date" columnDataType="${datetimeType}"/>
    </changeSet>

	<changeSet id="20252104104000-2" author="omg">
	  <createIndex 
	      indexName="idx_resilient_log__owner_id" 
	      tableName="resilient_log" 
	      unique="false">
	    <column name="owner_id"/>
	  </createIndex>
	</changeSet>
</databaseChangeLog>
