<?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-4.27.xsd">

  <changeSet id="0008-1-fix-dict-def-scope-uppercase" author="ordinis">
    <comment>JPA writes enum names UPPERCASE; original constraint accepted only lowercase. Replace.</comment>
    <sql>
      ALTER TABLE dictionary_definitions
        DROP CONSTRAINT IF EXISTS dictionary_definitions_scope_check;
      ALTER TABLE dictionary_definitions
        ADD CONSTRAINT dictionary_definitions_scope_check
        CHECK (scope IN ('PUBLIC', 'INTERNAL', 'RESTRICTED'));
    </sql>
  </changeSet>

  <changeSet id="0008-2-fix-dict-rec-scope-uppercase" author="ordinis">
    <comment>Same fix for dictionary_records.data_scope.</comment>
    <sql>
      ALTER TABLE dictionary_records
        DROP CONSTRAINT IF EXISTS dictionary_records_data_scope_check;
      ALTER TABLE dictionary_records
        ADD CONSTRAINT dictionary_records_data_scope_check
        CHECK (data_scope IN ('PUBLIC', 'INTERNAL', 'RESTRICTED'));
    </sql>
  </changeSet>

</databaseChangeLog>
