<?xml version="1.0" encoding="UTF-8"?>

<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
                      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="onlyoffice" id="1.0.0-1" onValidationFail="MARK_RAN">
    <preConditions onFail="MARK_RAN" onError="MARK_RAN">
      <not>
        <tableExists tableName="OO_EDITOR_CONFIG" />
      </not>
    </preConditions>
    <createTable tableName="OO_EDITOR_CONFIG">
      <column name="ID" type="BIGINT" autoIncrement="${autoIncrement}" startWith="1">
        <constraints nullable="false" primaryKey="true" primaryKeyName="PK_OO_EDITOR_CONFIG_ID" />
      </column>
      <column name="DOCUMENT_ID" type="VARCHAR(64)">
      </column>
      <column name="WORKSPACE" type="VARCHAR(250)">
      </column>
      <column name="PATH" type="VARCHAR(500)">
      </column>
      <column name="DOCUMENT_TYPE" type="VARCHAR(100)">
      </column>
      <column name="DOCUMENT_SERVER_URL" type="VARCHAR(250)">
      </column>
      <column name="PLATFORM_REST_URL" type="VARCHAR(250)">
      </column>
      <column name="EDITOR_URL" type="VARCHAR(250)">
      </column>
      <column name="DOWNLOAD_URL" type="VARCHAR(250)">
      </column>
      <column name="EXPLORER_URL" type="VARCHAR(250)">
      </column>
      <column name="IS_ACTIVITY" type="BOOLEAN" defaultValueBoolean="false">
      </column>
      <column name="ERROR" type="VARCHAR(500)">
      </column>
      <column name="OPEN" type="BOOLEAN">
      </column>
      <column name="CLOSING" type="BOOLEAN">
      </column>
      <column name="OPENED_TIME" type="BIGINT">
      </column>
      <column name="CLOSED_TIME" type="BIGINT">
      </column>
      <column name="EDITOR_PAGE_LAST_MODIFIER" type="VARCHAR(250)">
      </column>
      <column name="EDITOR_PAGE_LAST_MODIFIED" type="VARCHAR(250)">
      </column>
      <column name="EDITOR_PAGE_DISPLAY_PATH" type="VARCHAR(250)">
      </column>
      <column name="EDITOR_PAGE_COMMENT" type="VARCHAR(250)">
      </column>
      <column name="EDITOR_PAGE_DRIVE" type="VARCHAR(250)">
      </column>
      <column name="EDITOR_PAGE_RENAMED_ALLOWED" type="BOOLEAN">
      </column>
      <column name="DOCUMENT_FILETYPE" type="VARCHAR(250)">
      </column>
      <column name="DOCUMENT_KEY" type="VARCHAR(250)">
      </column>
      <column name="DOCUMENT_TITLE" type="VARCHAR(250)">
      </column>
      <column name="DOCUMENT_URL" type="VARCHAR(250)">
      </column>
      <column name="DOCUMENT_INFO_OWNER" type="VARCHAR(250)">
      </column>
      <column name="DOCUMENT_INFO_UPLOADED" type="VARCHAR(250)">
      </column>
      <column name="DOCUMENT_INFO_FOLDER" type="VARCHAR(250)">
      </column>
      <column name="PERMISSION_ALLOWEDIT" type="BOOLEAN">
      </column>
      <column name="EDITOR_CALLBACKURL" type="VARCHAR(250)">
      </column>
      <column name="EDITOR_LANG" type="VARCHAR(250)">
      </column>
      <column name="EDITOR_MODE" type="VARCHAR(250)">
      </column>
      <column name="EDITOR_USER_USERID" type="VARCHAR(250)">
      </column>
      <column name="EDITOR_USER_NAME" type="VARCHAR(250)">
      </column>
      <column name="EDITOR_USER_LASTMODIFIED" type="BIGINT">
      </column>
      <column name="EDITOR_USER_LASTSAVED" type="BIGINT">
      </column>
      <column name="EDITOR_USER_LINKSAVED" type="BIGINT">
      </column>
      <column name="EDITOR_USER_DOWNLOAD_LINK" type="VARCHAR(250)">
      </column>
    </createTable>
  </changeSet>

  <changeSet author="onlyoffice" id="1.0.0-2" dbms="oracle,postgresql">
    <createSequence sequenceName="SEQ_OO_EDITOR_CONFIG_ID" startValue="1"/>
  </changeSet>

  <changeSet author="onlyoffice" id="1.0.0-3">
    <modifyDataType columnName="EXPLORER_URL" newDataType="NVARCHAR(1000)" tableName="OO_EDITOR_CONFIG"/>
  </changeSet>

  <changeSet author="onlyoffice" id="1.0.0-4">
    <modifyDataType columnName="EDITOR_PAGE_COMMENT" newDataType="NVARCHAR(2000)" tableName="OO_EDITOR_CONFIG"/>
  </changeSet>

  <changeSet author="onlyoffice" id="1.0.0-5" dbms="hsqldb">
    <createSequence sequenceName="SEQ_OO_EDITOR_CONFIG_ID" startValue="1"/>
  </changeSet>
  <changeSet id="1.0.0-6" author="onlyoffice" dbms="mysql">
    <sql>ALTER TABLE OO_EDITOR_CONFIG MODIFY COLUMN DOCUMENT_TITLE varchar(250) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;</sql>
  </changeSet>

</databaseChangeLog>
