databaseChangeLog:
  - changeSet:
      id: create-table-component_mappings
      author: kilian
      changes:
        - createTable:
            tableName: component_mappings
            columns:
              - column:
                  name: id
                  type: VARCHAR(255)
                  constraints:
                    primaryKey: true
              - column:
                  name: dossier_template_id
                  type: VARCHAR(255)
                  constraints:
                    nullable: false
              - column:
                  name: storage_id
                  type: VARCHAR(255)
                  constraints:
                    nullable: false
              - column:
                  name: name
                  type: VARCHAR(255)
                  constraints:
                    nullable: false
              - column:
                  name: file_name
                  type: VARCHAR(255)
                  constraints:
                    nullable: false
              - column:
                  name: version
                  type: integer
                  constraints:
                    nullable: false
                  defaultValue: '-1'
              - column:
                  name: changed_date
                  type: TIMESTAMP WITH TIME ZONE
                  constraints:
                    nullable: false
              - column:
                  name: number_of_lines
                  type: INTEGER
                  constraints:
                    nullable: false
                  defaultValue: '0'
              - column:
                  name: encoding
                  type: VARCHAR(255)
                  constraints:
                    nullable: false
                  defaultValue: 'UTF-8'
              - column:
                  name: delimiter
                  type: CHAR(1)
                  constraints:
                    nullable: false
                  defaultValue: ','
        - addUniqueConstraint:
            columnNames: name, dossier_template_id
            constraintName: unique_name_dossier_template
            tableName: component_mappings
        - addForeignKeyConstraint:
            baseColumnNames: dossier_template_id
            baseTableName: component_mappings
            constraintName: fk_entity_dossier_template_id
            referencedColumnNames: id
            referencedTableName: dossier_template
            onDelete: CASCADE
            onUpdate: CASCADE

        - createTable:
            tableName: component_mapping_column_labels
            columns:
              - column:
                  name: component_mapping_entity_id
                  type: VARCHAR(255)
                  constraints:
                    nullable: false
              - column:
                  name: column_labels
                  type: VARCHAR(255)
                  constraints:
                    nullable: false

        - addForeignKeyConstraint:
            baseColumnNames: component_mapping_entity_id
            baseTableName: component_mapping_column_labels
            constraintName: fk_component_mapping_column_labels_entity_id
            referencedColumnNames: id
            referencedTableName: component_mappings
            onDelete: CASCADE
            onUpdate: CASCADE
