databaseChangeLog:
  - logicalFilePath: db-changelog-001045-create-rc-screen-design-obj-ref-table.yaml
  - changeSet:
      author: appian
      id: tag-pre-001045
      tagDatabase:
        tag: 'pre-001045'
  - changeSet:
      author: appian
      id: '001045.0.0'
      comment: Create rc_screen_design_obj_ref table
      changes:
        - createTable:
            tableName: rc_screen_design_obj_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_qname
                  type: ${shortStringType}
                  constraints:
                    nullable: false
              - column:
                  name: req_capture_ux_plan_screen_id
                  type: ${longType}
                  constraints:
                    nullable: false

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

  - changeSet:
      id: '001045.0.2'
      author: appian
      comment: Add foreign key constraint to req_capture_ux_plan_screen_id field in rc_screen_design_obj_ref table
      changes:
        - addForeignKeyConstraint:
            constraintName: obj_ref_rc_screen_id_fk
            baseTableName: rc_screen_design_obj_ref
            baseColumnNames: req_capture_ux_plan_screen_id
            referencedTableName: req_capture_ux_plan_screen
            referencedColumnNames: id
            onDelete: CASCADE

  - changeSet:
      id: '001045.0.3'
      author: appian
      comment: Adds a composite uniqueness constraint to the req_capture_ux_plan_screen_id and design_object_uuid fields
      changes:
        - addUniqueConstraint:
            constraintName: rc_screen_design_object_ref_uc
            tableName: rc_screen_design_obj_ref
            columnNames: design_object_uuid, req_capture_ux_plan_screen_id
