databaseChangeLog:
  - changeSet:
      id: modify_fk_constraints_of_manual_changes_to_cascade_delete
      author: kilian
      changes:
        - dropForeignKeyConstraint:
            baseTableName: id_removal_entity_type_ids_of_modified_dictionaries # id_removal -> modified dictionaries
            constraintName: fk64e6qfq7tqad3lknqmqpzzz
        - dropForeignKeyConstraint:
            baseTableName: manual_recategorization_type_ids_of_dictionaries_with_add # recategorization -> modified dictionaries (add)
            constraintName: fk_manual_recategorization_to_dictionary_add
        - dropForeignKeyConstraint:
            baseTableName: manual_recategorization_type_ids_of_dictionaries_with_delete # recategorization -> modified dictionaries (delete)
            constraintName: fk_manual_recategorization_to_dictionary_delete
        - dropForeignKeyConstraint:
            baseTableName: manual_redaction_entry_entity_positions # manual_redaction -> positions
            constraintName: fkol1r7vwjc1uvu36p5ju7cj28h
        - dropForeignKeyConstraint:
            baseTableName: manual_redaction_entry_entity_type_ids_of_modified_dictionaries # manual_redaction -> modified dictionaries
            constraintName: fk64e6qfq7tqad3lknqmqpzaa
        - dropForeignKeyConstraint:
            baseTableName: manual_resize_redaction_entity_positions # resize -> positions
            constraintName: fkf0yltiuicrfxj62kbnq5fi5c8
        - dropForeignKeyConstraint:
            baseTableName: manual_resize_redaction_entity_type_ids_of_modified_dictionarie # resize -> modified dictionaries
            constraintName: fk_resize_entity_annotation_id_file_id_for_type_ids_of_modified


  - changeSet:
      id: modify_fk_constraints_of_manual_changes_to_cascade_delete_2
      author: kilian
      changes:
        - addForeignKeyConstraint: # id_removal -> modified dictionaries
            constraintName: FK_id_removal_entity_type_ids
            baseTableName: id_removal_entity_type_ids_of_modified_dictionaries
            baseColumnNames: id_removal_entity_annotation_id, id_removal_entity_file_id
            referencedTableName: id_removal
            referencedColumnNames: annotation_id, file_id
            deferrable: false
            initiallyDeferred: false
            onDelete: CASCADE
            onUpdate: CASCADE
            validate: true
        - addForeignKeyConstraint: # recategorization -> modified dictionaries (add)
            constraintName: fk_manual_recategorization_to_dictionary_add
            baseTableName: manual_recategorization_type_ids_of_dictionaries_with_add
            baseColumnNames: manual_recategorization_entity_annotation_id, manual_recategorization_entity_file_id
            referencedTableName: manual_recategorization
            referencedColumnNames: annotation_id, file_id
            deferrable: false
            initiallyDeferred: false
            onDelete: CASCADE
            onUpdate: CASCADE
            validate: true
        - addForeignKeyConstraint: # recategorization -> modified dictionaries (delete)
            constraintName: fk_manual_recategorization_to_dictionary_delete
            baseTableName: manual_recategorization_type_ids_of_dictionaries_with_delete
            baseColumnNames: manual_recategorization_entity_annotation_id, manual_recategorization_entity_file_id
            referencedTableName: manual_recategorization
            referencedColumnNames: annotation_id, file_id
            deferrable: false
            initiallyDeferred: false
            onDelete: CASCADE
            onUpdate: CASCADE
            validate: true
        - addForeignKeyConstraint:
            constraintName: fk_manual_redaction_to_positions # manual_redaction -> positions
            baseTableName: manual_redaction_entry_entity_positions
            baseColumnNames: manual_redaction_entry_entity_annotation_id, manual_redaction_entry_entity_file_id
            referencedTableName: manual_redaction
            referencedColumnNames: annotation_id, file_id
            deferrable: false
            initiallyDeferred: false
            onDelete: CASCADE
            onUpdate: CASCADE
            validate: true
        - addForeignKeyConstraint:
            constraintName: fk_manual_redaction_to_dictionaries # manual_redaction -> modified dictionaries
            baseTableName: manual_redaction_entry_entity_type_ids_of_modified_dictionaries
            baseColumnNames: manual_redaction_entry_entity_annotation_id, manual_redaction_entry_entity_file_id
            referencedTableName: manual_redaction
            referencedColumnNames: annotation_id, file_id
            deferrable: false
            initiallyDeferred: false
            onDelete: CASCADE
            onUpdate: CASCADE
            validate: true
        - addForeignKeyConstraint:
            constraintName: fk_manual_resize_to_positions # manual resize -> positions
            baseTableName: manual_resize_redaction_entity_positions
            baseColumnNames: manual_resize_redaction_entity_annotation_id, manual_resize_redaction_entity_file_id
            referencedTableName: manual_resize_redaction
            referencedColumnNames: annotation_id, file_id
            deferrable: false
            initiallyDeferred: false
            onDelete: CASCADE
            onUpdate: CASCADE
            validate: true
        - addForeignKeyConstraint:
            constraintName: fk_manual_resize_to_dictionaries # manual resize -> modified dictionaries
            baseTableName: manual_resize_redaction_entity_type_ids_of_modified_dictionarie
            baseColumnNames: manual_resize_redaction_entity_annotation_id, manual_resize_redaction_entity_file_id
            referencedTableName: manual_resize_redaction
            referencedColumnNames: annotation_id, file_id
            deferrable: false
            initiallyDeferred: false
            onDelete: CASCADE
            onUpdate: CASCADE
            validate: true


  - changeSet:
      id: delete-unapproved-manual-changes
      author: kilian
      changes:
        - delete:
            tableName: manual_redaction
            where: "status != 'APPROVED'"
        - delete:
            tableName: manual_force_redaction
            where: "status != 'APPROVED'"
        - delete:
            tableName: manual_recategorization
            where: "status != 'APPROVED'"
        - delete:
            tableName: manual_legal_basis_change
            where: "status != 'APPROVED'"
        - delete:
            tableName: manual_resize_redaction
            where: "status != 'APPROVED'"
        - delete:
            tableName: id_removal
            where: "status != 'APPROVED'"

  - changeSet:
      id: remove-status-column
      author: kilian
      changes:
        - dropColumn:
            tableName: manual_redaction
            columnName: status
        - dropColumn:
            tableName: manual_force_redaction
            columnName: status
        - dropColumn:
            tableName: manual_recategorization
            columnName: status
        - dropColumn:
            tableName: manual_legal_basis_change
            columnName: status
        - dropColumn:
            tableName: manual_resize_redaction
            columnName: status
        - dropColumn:
            tableName: id_removal
            columnName: status
