databaseChangeLog:
  - logicalFilePath: db-changelog-000369-add-portal-publish-info.yaml

  - changeSet:
      id: 'tag-pre-000369'
      author: appian
      tagDatabase:
        tag: 'pre-000369'

  - changeSet:
      id: '000369.1.0'
      author: appian
      comment: Create the portal_publish_info table
      changes:
        - createTable:
            tableName: portal_publish_info
            columns:
              - column:
                  name: id
                  type: ${longType}
                  autoIncrement: ${autoIncrement}
                  constraints:
                    nullable: false
                    primaryKey: true
              - column:
                  name: portal_uuid
                  type: ${uuidType}
                  constraints:
                    nullable: false
                    unique: true
                    uniqueConstraintName: portal_publish_info_puuid_uc
              - column:
                  name: status
                  type: ${byteType}
                  constraints:
                    nullable: false
              - column:
                  name: serverless_webapp_uuid
                  type: ${uuidType}
                  constraints:
                    nullable: true
              - column:
                  name: last_computed_url_stub
                  type: ${mediumStringType}
                  constraints:
                    nullable: true
              - column:
                  name: last_full_url
                  type: ${mediumStringType}
                  constraints:
                    nullable: true
              - column:
                  name: test_uuid
                  type: ${uuidType}
                  constraints:
                    nullable: false
                    unique: true
                    uniqueConstraintName: portal_publish_info_tuuid_uc
              - column:
                  name: created_ts
                  type: ${longType}
                  constraints:
                    nullable: false
              - column:
                  name: created_by
                  type: ${longType}
                  constraints:
                    nullable: false
              - column:
                  name: updated_ts
                  type: ${longType}
                  constraints:
                    nullable: false
              - column:
                  name: updated_by
                  type: ${longType}
                  constraints:
                    nullable: false
        - addForeignKeyConstraint:
            constraintName: portal_publish_info_crt_by_fk
            baseTableName: portal_publish_info
            baseColumnNames: created_by
            referencedTableName: usr
            referencedColumnNames: id
        - addForeignKeyConstraint:
            constraintName: portal_publish_info_upd_by_fk
            baseTableName: portal_publish_info
            baseColumnNames: updated_by
            referencedTableName: usr
            referencedColumnNames: id

  - changeSet:
      id: '000369.1.1'
      comment: A sequence to provide primary key values for the portal_publish_info table
      author: appian
      changes:
        - preConditions:
            onFail: MARK_RAN
            changeLogPropertyDefined:
              property: createSequence
              value: true
        - createSequence:
            sequenceName: portal_publish_info_sq

  - changeSet:
      id: '000369.1.2'
      author: appian
      comment: Add publishing-related columns to the portal table
      changes:
        - addColumn:
            tableName: portal
            columns:
              - column:
                  name: service_acct_user_uuid
                  type: ${uuidType}
                  constraints:
                    nullable: true
              - column:
                  name: is_captcha_used
                  type: ${booleanType}
                  constraints:
                    nullable: true
              - column:
                  name: captcha_site_key
                  type: ${shortStringType}
                  constraints:
                    nullable: true
              - column:
                  name: captcha_api_key
                  type: ${shortStringType}
                  constraints:
                    nullable: true
              - column:
                  name: captcha_project_id
                  type: ${shortStringType}
                  constraints:
                    nullable: true
              - column:
                  name: publish_info_id
                  type: ${longType}
                  # DB2 requires a default value here, but then we remove it below
                  # See https://docs.google.com/document/d/1N3AIu0s7SAMBIdoIR5vUYSvkAZyRVOuHa8ODHjb86WM/edit#bookmark=kix.teippu4al6z
                  defaultValue: 0
                  constraints:
                    nullable: false
                    unique: true
                    uniqueConstraintName: portal_publish_info_id_uc
        - addForeignKeyConstraint:
            constraintName: portal_publish_info_id_fk
            baseTableName: portal
            baseColumnNames: publish_info_id
            referencedTableName: portal_publish_info
            referencedColumnNames: id

  - changeSet:
      id: '000369.1.3'
      author: appian
      comment: Remove the unwanted default value that we were obliged to add above
      dropDefaultValue:
        tableName: portal
        columnName: publish_info_id
        columnDataType: ${longType}
