databaseChangeLog:
  - logicalFilePath: db-changelog-001022-create-rc-entity-design-object-ref-table.yaml
  - changeSet:
      author: appian
      id: tag-pre-001022
      tagDatabase:
        tag: 'pre-001022'
  - changeSet:
      author: appian
      id: '001022.0.0'
      comment: Create rc_entity_design_object_ref table
      changes:
        - createTable:
            tableName: rc_entity_design_object_ref
            columns:
              - column:
                  name: id
                  type: ${longtype}
                  autoIncrement: ${autoIncrement}
                  constraints:
                    primaryKey: true
                    nullable: false
              - column:
                  name: design_object_uuid
                  type: ${shortStringType}
                  constraints:
                    nullable: false
              - column:
                  name: design_object_type_qname
                  type: ${shortStringType}
                  constraints:
                    nullable: false
              - column:
                  name: req_capture_entity_id
                  type: ${longtype}
                  constraints:
                    nullable: false

  - changeSet:
      id: '001022.0.1'
      author: appian
      comment: Create a sequence to provide primary key values for the rc_entity_design_object_ref table
      preConditions:
        onFail: MARK_RAN
        changeLogPropertyDefined:
          property: createSequence
          value: true
      changes:
        createSequence:
          sequenceName: rc_entity_design_object_ref_sq

  - changeSet:
      id: '001022.0.2'
      author: appian
      comment: Add foreign key constraint to id field in req_capture_entity table
      changes:
        - addForeignKeyConstraint:
            constraintName: rc_entity_do_ref_rce_id_fk
            baseTableName: rc_entity_design_object_ref
            baseColumnNames: req_capture_entity_id
            referencedTableName: req_capture_entity
            referencedColumnNames: id
            onDelete: CASCADE

  - changeSet:
      id: '001022.0.3'
      author: appian
      comment: Adds a composite uniqueness constraint to the req_capture_entity_id and design_object_uuid fields
      changes:
        - addUniqueConstraint:
            constraintName: rc_entity_do_ref_uuid_rceid_uc
            tableName: rc_entity_design_object_ref
            columnNames: design_object_uuid, req_capture_entity_id

  - changeSet:
      author: appian
      id: '001022.0.4'
      comment: Add sort_order column to req_cap_entity_attribute table
      changes:
        - addColumn:
            tableName: req_cap_entity_attribute
            columns:
              - column:
                  name: sort_order
                  type: ${integerType}
                  defaultValue: 0
                  valueNumeric: 0
                  constraints:
                    nullable: false
