databaseChangeLog:
  - logicalFilePath: db-changelog-000539-delete-reaper-rows-qrtz.yaml
  - changeSet:
      author: appian
      id: tag-pre-000539
      tagDatabase:
        tag: 'pre-000539'

  # AN-201043 This migration deletes the existing reaper CRON trigger so that the trigger can be remade as a
  # SIMPLE trigger.

  # The following tables (QRTZ_BLOB_TRIGGERS, QRTZ_CRON_TRIGGERS, QRTZ_SIMPLE_TRIGGERS, QRTZ_SIMPROP_TRIGGERS) have a foreign key
  # constraint on QRTZ_TRIGGERS so these rows must be deleted first.
  - changeSet:
      author: appian
      id: '000539.1.0'
      comment: Remove reaper rows from QRTZ_BLOB_TRIGGERS
      changes:
        - delete:
            tableName: QRTZ_BLOB_TRIGGERS
            where: TRIGGER_NAME='record_replica_reaper'

  - changeSet:
      author: appian
      id: '000539.1.1'
      comment: Remove reaper rows from QRTZ_CRON_TRIGGERS
      changes:
        - delete:
            tableName: QRTZ_CRON_TRIGGERS
            where: TRIGGER_NAME='record_replica_reaper'

  - changeSet:
      author: appian
      id: '000539.1.2'
      comment: Remove reaper rows from QRTZ_SIMPLE_TRIGGERS
      changes:
        - delete:
            tableName: QRTZ_SIMPLE_TRIGGERS
            where: TRIGGER_NAME='record_replica_reaper'

  - changeSet:
      author: appian
      id: '000539.1.3'
      comment: Remove reaper rows from QRTZ_SIMPROP_TRIGGERS
      changes:
        - delete:
            tableName: QRTZ_SIMPROP_TRIGGERS
            where: TRIGGER_NAME='record_replica_reaper'

  # QRTZ_TRIGGERS has a foreign key constraint on QRTZ_JOB_DETAILS so its rows must be deleted first.
  - changeSet:
      author: appian
      id: '000539.1.4'
      comment: Remove reaper rows from QRTZ_TRIGGERS
      changes:
        - delete:
            tableName: QRTZ_TRIGGERS
            where: TRIGGER_NAME='record_replica_reaper'

  - changeSet:
      author: appian
      id: '000539.1.5'
      comment: Remove reaper rows from QRTZ_JOB_DETAILS
      changes:
        - delete:
            tableName: QRTZ_JOB_DETAILS
            where: JOB_NAME='record_replica_reaper'

  - changeSet:
      author: appian
      id: '000539.1.6'
      comment: Remove reaper rows from QRTZ_FIRED_TRIGGERS
      changes:
        - delete:
            tableName: QRTZ_FIRED_TRIGGERS
            where: TRIGGER_NAME='record_replica_reaper'
