/*
 Migrates the Airlock IAM DB schema from version 8.1 to version 8.2.
 Written for PostgreSQL.
*/
CREATE TABLE oauth2_consent
(
    id                      VARCHAR(36)  NOT NULL,
    user_id                 VARCHAR(100) NOT NULL,
    authorization_server_id VARCHAR(50)  NOT NULL,
    client_id               VARCHAR(50)  NOT NULL,
    scope_name              VARCHAR(50)  NOT NULL,
    status                  VARCHAR(20)  NOT NULL,
    updated_at              BIGINT       NOT NULL,
    tenant_id               VARCHAR(50)  NOT NULL
);
-- Additional indexes
CREATE UNIQUE INDEX ux_oauth2_consent_id
    ON oauth2_consent (id);

CREATE INDEX ix_oauth2_consent_user_as_client
    ON oauth2_consent (user_id, authorization_server_id, client_id);
