<?xml version="1.0" encoding="UTF-8"?>
<!--
 * Copyright (C) 2023 eXo Platform SAS.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 *
-->
<databaseChangeLog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                   xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
                      http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.4.xsd">

    <!-- Managing both DB that use sequences and db that use auto increment -->
    <property name="autoIncrement" value="true" dbms="mysql,mssql,h2,sybase,db2,hsqldb"/>
    <property name="autoIncrement" value="false" dbms="oracle,postgresql"/>

    <!-- Managing auto generation of timestamp by Database -->
    <property name="now" value="now()" dbms="mysql,hsqldb,postgresql,h2"/>
    <property name="now" value="sysdate" dbms="oracle"/>
    <property name="now" value="CURRENT_TIMESTAMP" dbms="mssql"/>


    <changeSet author="documents" id="1.0.0-0">
        <createTable tableName="DOCUMENTS_PUBLIC_ACCESS">
            <column name="ID" type="BIGINT" autoIncrement="${autoIncrement}" startWith="1">
                <constraints nullable="false" primaryKey="true" primaryKeyName="PK_DOCUMENT_PUBLIC_ACCESS"/>
            </column>
            <column name="NODE_ID" type="NVARCHAR(250)">
                <constraints nullable="false"/>
            </column>
            <column name="PASSWORD_HASH_KEY" type="NVARCHAR(2000)" />
            <column name="ENCODED_PASSWORD" type="NVARCHAR(1000)" />
            <column name="EXPIRATION_DATE" type="TIMESTAMP"/>
        </createTable>
        <modifySql dbms="mysql">
            <append value=" ENGINE=INNODB CHARSET=UTF8 COLLATE utf8_general_ci"/>
        </modifySql>
    </changeSet>

    <changeSet author="documents" id="1.0.0-1" dbms="hsqldb,oracle,postgresql">
        <createSequence sequenceName="SEQ_DOCUMENT_PUBLIC_ACCESS_ID" startValue="1"/>
    </changeSet>

</databaseChangeLog>
