<?xml version="1.0" 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 http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-2.0.xsd"
                   logicalFilePath="db-changelog-000165-rename-system-column-webapi.xml">

  <changeSet author="appian" id="tag-000164">
    <tagDatabase tag="000164"/>
  </changeSet>

  <changeSet author="appian" id="000165.1.0">
    <comment>Update system column name and recreate indices with is_system column name.</comment>

    <dropIndex indexName="webapi_name_uc" tableName="web_api"/>
    <dropIndex indexName="webapi_aliasmethod_idx" tableName="web_api"/>

    <!--Referencing the column datatype as ${booleanType} results in a failure on MYSQL,
    so we will use TINYINT(1) instead. This property should not be referenced by other database migrations.-->
    <renameColumn tableName="web_api" oldColumnName="system" newColumnName="is_system"
                  columnDataType="TINYINT(1)"/>

    <createIndex indexName="webapi_name_uc" tableName="web_api" unique="true">
      <column name="name"/>
      <column name="is_system"/>
    </createIndex>

    <createIndex indexName="webapi_aliasmethod_idx" tableName="web_api" unique="true">
      <column name="url_alias"/>
      <column name="http_method"/>
      <column name="is_system"/>
    </createIndex>
  </changeSet>

</databaseChangeLog>
