<?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-000024.xml">

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

  <changeSet author="appian" id="000024.1.0">
    <comment>Create role map table for record_type.</comment>
    <createTable tableName="record_type_rm">
      <column name="record_type_id" type="${longType}">
        <constraints nullable="false"/>
      </column>
      <column name="rm_entry_id" type="${longType}">
        <constraints nullable="false"/>
      </column>
    </createTable>
    <modifySql dbms="mysql">
      <append value="${mysqlEngineSql}"/>
    </modifySql>
  </changeSet>
  <changeSet author="appian" id="000024.1.1">
    <comment>Add PK for record_type_rm.</comment>
    <addPrimaryKey columnNames="record_type_id, rm_entry_id" tableName="record_type_rm"/>
  </changeSet>
  <changeSet author="appian" id="000024.1.2">
    <comment>Add FK from record_type_rm to rm_entry.id.</comment>
    <addForeignKeyConstraint constraintName="record_type_rm_rmeid_fk"
      baseTableName="record_type_rm" baseColumnNames="rm_entry_id"
      referencedTableName="rm_entry" referencedColumnNames="id"
      deferrable="false" initiallyDeferred="false" referencesUniqueColumn="false"/>
  </changeSet>
  <changeSet author="appian" id="000024.1.3">
    <comment>Add FK from record_type_rm to record_type.id.</comment>
    <addForeignKeyConstraint constraintName="record_type_rm_rtid_fk"
      baseTableName="record_type_rm" baseColumnNames="record_type_id"
      referencedColumnNames="id" referencedTableName="record_type"
      deferrable="false" initiallyDeferred="false" referencesUniqueColumn="false"/>
  </changeSet>
  <changeSet author="appian" id="000024.1.4">
    <validCheckSum></validCheckSum>
    <preConditions onFail="MARK_RAN"><not><or><dbms type="mysql"/><dbms type="mariadb"/></or></not></preConditions>
    <comment>Create an index for the FK column record_type_rm.rm_entry_id</comment>
    <createIndex indexName="record_type_rm_rmei_idx" tableName="record_type_rm" unique="false">
      <column name="rm_entry_id"/>
    </createIndex>
  </changeSet>


  <changeSet author="appian" id="000024.2.0">
    <comment>Add a system role (in rm_role) for Record Type viewers.</comment>
    <insert tableName="rm_role">
      <column name="id" value="6"/>
      <column name="name" value="record_type_viewer"/>
    </insert>
  </changeSet>
  <changeSet author="appian" id="000024.2.1">
    <comment>Add a system role (in rm_role) for Record Type administrators.</comment>
    <insert tableName="rm_role">
      <column name="id" value="7"/>
      <column name="name" value="record_type_administrator"/>
    </insert>
  </changeSet>
  <changeSet author="appian" id="000024.2.2">
    <comment>Add a system role (in rm_role) for Record Type editors.</comment>
    <insert tableName="rm_role">
      <column name="id" value="8"/>
      <column name="name" value="record_type_editor"/>
    </insert>
  </changeSet>
  <changeSet author="appian" id="000024.2.3">
    <comment>Add a system role (in rm_role) for Record Type auditors.</comment>
    <insert tableName="rm_role">
      <column name="id" value="9"/>
      <column name="name" value="record_type_auditor"/>
    </insert>
  </changeSet>
</databaseChangeLog>
