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

-- Comment out 'SET sqlblanklines on' if you're using a SQL client other than Oracle SQL*Plus
SET sqlblanklines on

ALTER SESSION SET NLS_LENGTH_SEMANTICS='CHAR';

CREATE TABLE flow_continuation_token
(
    pk                    NUMBER(19)    NOT NULL,
    token_hash            VARCHAR2(86)  NOT NULL,
    user_id               VARCHAR2(100) NOT NULL,
    target_flow_id        VARCHAR2(30)  NOT NULL,
    created_at            NUMBER(19)    NOT NULL,
    valid_until           NUMBER(19)    NOT NULL,
    configuration_context VARCHAR2(50)  NOT NULL,
    forward_url           VARCHAR2(200),
    tenant_id             VARCHAR2(50)  NOT NULL,

    CONSTRAINT pk_flow_continuation_token PRIMARY KEY (pk)
);
-- Sequence for pk
CREATE SEQUENCE flow_continuation_token_seq
    MINVALUE 1
    START WITH 1
    INCREMENT BY 1
    NOCACHE;

-- Additional indexes
CREATE UNIQUE INDEX ux_flow_continuation_token ON flow_continuation_token (token_hash);
