/*
 Migrates the Airlock IAM DB schema from version 7.6 to version 7.7.
 Written for MySQL.
 */

ALTER TABLE last_selection
    MODIFY COLUMN selected_at DATETIME(6) NOT NULL;

CREATE TABLE flow_continuation_token
(
    pk                    BIGINT                                  NOT NULL AUTO_INCREMENT,
    token_hash            VARCHAR(86) COLLATE utf8mb4_0900_bin    NOT NULL,
    user_id               VARCHAR(100) COLLATE utf8mb4_0900_ai_ci NOT NULL,
    target_flow_id        VARCHAR(30) COLLATE utf8mb4_0900_bin    NOT NULL,
    created_at            BIGINT                                  NOT NULL,
    valid_until           BIGINT                                  NOT NULL,
    configuration_context VARCHAR(50) COLLATE utf8mb4_0900_bin    NOT NULL,
    forward_url           VARCHAR(200) COLLATE utf8mb4_0900_ai_ci,
    tenant_id             VARCHAR(50) COLLATE utf8mb4_0900_bin    NOT NULL,

    CONSTRAINT pk_flow_continuation_token PRIMARY KEY (pk)
) CHARACTER SET utf8mb4
  COLLATE utf8mb4_0900_ai_ci;
-- Additional indexes
CREATE UNIQUE INDEX ux_flow_continuation_token ON flow_continuation_token (token_hash);
