CREATE TABLE SP_TRUSTED_APPS (
			ID INTEGER NOT NULL,
			SP_ID INTEGER NOT NULL,
			PLATFORM_TYPE VARCHAR(255) NOT NULL,
			APP_IDENTIFIER VARCHAR(255) NOT NULL,
			THUMBPRINTS VARCHAR(2048),
			IS_FIDO_TRUSTED NUMBER(1,0) DEFAULT 0,
			TENANT_ID INTEGER NOT NULL,
			PRIMARY KEY (ID),
			UNIQUE (SP_ID, PLATFORM_TYPE),
			FOREIGN KEY (SP_ID) REFERENCES SP_APP(ID) ON DELETE CASCADE)
/
CREATE SEQUENCE SP_TRUSTED_APPS_SEQ START WITH 1 INCREMENT BY 1 NOCACHE
/
CREATE OR REPLACE TRIGGER SP_TRUSTED_APPS_TRIG
            BEFORE INSERT
            ON SP_TRUSTED_APPS
            REFERENCING NEW AS NEW
            FOR EACH ROW
                BEGIN
                    SELECT SP_TRUSTED_APPS_SEQ.nextval INTO :NEW.ID FROM dual;
                END;
/
CREATE TABLE IDN_NOTIFICATION_TYPE (
    ID INTEGER NOT NULL,
    TYPE_KEY VARCHAR(255) NOT NULL,
    NAME VARCHAR(255) NOT NULL,
    CHANNEL VARCHAR(255) NOT NULL,
    TENANT_ID INTEGER NOT NULL,
    PRIMARY KEY (ID),
    CONSTRAINT NOTIFICATION_TYPE_KEY_CONSTRAINT UNIQUE (TYPE_KEY, CHANNEL, TENANT_ID),
    CONSTRAINT NOTIFICATION_TYPE_NAME_CONSTRAINT UNIQUE (NAME, CHANNEL, TENANT_ID)
)
/
CREATE SEQUENCE IDN_NOTIFICATION_TYPE_SEQ START WITH 1 INCREMENT BY 1 NOCACHE
/
CREATE OR REPLACE TRIGGER IDN_NOTIFICATION_TYPE_TRIG
            BEFORE INSERT
            ON IDN_NOTIFICATION_TYPE
            REFERENCING NEW AS NEW
            FOR EACH ROW
              BEGIN
                SELECT IDN_NOTIFICATION_TYPE_SEQ.nextval INTO :NEW.ID FROM dual;
              END;
/
CREATE TABLE IDN_NOTIFICATION_ORG_TEMPLATE (
    ID INTEGER NOT NULL,
    TEMPLATE_KEY VARCHAR(50) NOT NULL,
    LOCALE VARCHAR(50) NOT NULL,
    CONTENT BLOB NOT NULL,
    CONTENT_TYPE VARCHAR(50),
    TYPE_ID INTEGER NOT NULL,
    TENANT_ID INTEGER NOT NULL,
    PRIMARY KEY (ID),
    FOREIGN KEY (TYPE_ID) REFERENCES IDN_NOTIFICATION_TYPE(ID) ON DELETE CASCADE,
    CONSTRAINT ORG_NOTIFICATION_TEMPLATE_KEY_CONSTRAINT UNIQUE (TEMPLATE_KEY, TYPE_ID, TENANT_ID),
    CONSTRAINT ORG_NOTIFICATION_TEMPLATE_LOCALE_CONSTRAINT UNIQUE (LOCALE, TYPE_ID, TENANT_ID)
)
/
CREATE SEQUENCE IDN_NOTIFICATION_ORG_TEMPLATE_SEQ START WITH 1 INCREMENT BY 1 NOCACHE
/
CREATE OR REPLACE TRIGGER IDN_NOTIFICATION_ORG_TEMPLATE_TRIG
            BEFORE INSERT
            ON IDN_NOTIFICATION_ORG_TEMPLATE
            REFERENCING NEW AS NEW
            FOR EACH ROW
              BEGIN
                SELECT IDN_NOTIFICATION_ORG_TEMPLATE_SEQ.nextval INTO :NEW.ID FROM dual;
              END;
/
CREATE TABLE IDN_NOTIFICATION_APP_TEMPLATE (
    ID INTEGER NOT NULL,
    TEMPLATE_KEY VARCHAR(50) NOT NULL,
    LOCALE VARCHAR(50) NOT NULL,
    CONTENT BLOB NOT NULL,
    CONTENT_TYPE VARCHAR(50),
    TYPE_ID INTEGER NOT NULL,
    APP_ID VARCHAR(255) NOT NULL,
    TENANT_ID INTEGER NOT NULL,
    PRIMARY KEY (ID),
    FOREIGN KEY (TYPE_ID) REFERENCES IDN_NOTIFICATION_TYPE(ID) ON DELETE CASCADE,
    CONSTRAINT APP_NOTIFICATION_TEMPLATE_KEY_CONSTRAINT UNIQUE (TEMPLATE_KEY, TYPE_ID, APP_ID, TENANT_ID),
    CONSTRAINT APP_NOTIFICATION_TEMPLATE_LOCALE_CONSTRAINT UNIQUE (LOCALE, TYPE_ID, APP_ID, TENANT_ID)
)
/
CREATE SEQUENCE IDN_NOTIFICATION_APP_TEMPLATE_SEQ START WITH 1 INCREMENT BY 1 NOCACHE
/
CREATE OR REPLACE TRIGGER IDN_NOTIFICATION_APP_TEMPLATE_TRIG
            BEFORE INSERT
            ON IDN_NOTIFICATION_APP_TEMPLATE
            REFERENCING NEW AS NEW
            FOR EACH ROW
              BEGIN
                SELECT IDN_NOTIFICATION_APP_TEMPLATE_SEQ.nextval INTO :NEW.ID FROM dual;
              END;
/
CREATE TABLE IDN_ACTION (
    UUID CHAR(36) NOT NULL,
    TYPE VARCHAR(50) NOT NULL,
    NAME VARCHAR(255) NOT NULL,
    DESCRIPTION VARCHAR(255),
    STATUS VARCHAR(10) NOT NULL,
    TENANT_ID INTEGER NOT NULL,
    PRIMARY KEY (UUID)
)
/
CREATE TABLE IDN_ACTION_PROPERTIES (
    ACTION_UUID CHAR(36) NOT NULL,
    PROPERTY_NAME VARCHAR(100) NOT NULL,
    PROPERTY_VALUE VARCHAR(255) NOT NULL,
    TENANT_ID INTEGER NOT NULL,
    PRIMARY KEY (ACTION_UUID, PROPERTY_NAME),
    FOREIGN KEY (ACTION_UUID) REFERENCES IDN_ACTION(UUID) ON DELETE CASCADE
)
/
CREATE TABLE IDN_OAUTH2_TOKEN_CLAIMS (
  ID INTEGER,
  APP_ID INTEGER NOT NULL,
  CLAIM_URI VARCHAR(255) NOT NULL,
  PRIMARY KEY (ID),
  CONSTRAINT TOKEN_CLAIMS_CONSTRAINT UNIQUE (APP_ID, CLAIM_URI),
  FOREIGN KEY (APP_ID) REFERENCES IDN_OAUTH_CONSUMER_APPS(ID) ON DELETE CASCADE
)
/
CREATE SEQUENCE IDN_OAUTH2_TOKEN_CLAIMS_SEQ START WITH 1 INCREMENT BY 1 NOCACHE
/
CREATE OR REPLACE TRIGGER IDN_OAUTH2_TOKEN_CLAIMS_TRIG
  BEFORE INSERT
    ON IDN_OAUTH2_TOKEN_CLAIMS
    REFERENCING NEW AS NEW
    FOR EACH ROW
  BEGIN
  SELECT IDN_OAUTH2_TOKEN_CLAIMS_SEQ.nextval INTO :NEW.ID FROM dual;
  END;
/

CREATE TABLE IDN_XACML_CONFIG (
    CONFIG_KEY VARCHAR(255) NOT NULL,
    CONFIG_VALUE VARCHAR(255) NOT NULL,
    TENANT_ID INTEGER NOT NULL,
    PRIMARY KEY (TENANT_ID, CONFIG_KEY)
)
/

CREATE TABLE IDN_XACML_POLICY (
    POLICY_ID VARCHAR(255) NOT NULL,
    VERSION INTEGER NOT NULL,
    IS_IN_PAP CHAR(1) DEFAULT '1' NOT NULL,
    IS_IN_PDP CHAR(1) DEFAULT '0' NOT NULL,
    POLICY CLOB NOT NULL,
    IS_ACTIVE CHAR(1) DEFAULT '0' NOT NULL,
    POLICY_TYPE VARCHAR(255) NOT NULL,
    POLICY_EDITOR VARCHAR(255),
    POLICY_ORDER INTEGER NOT NULL,
    LAST_MODIFIED_TIME TIMESTAMP NOT NULL,
    LAST_MODIFIED_USER VARCHAR(255),
    TENANT_ID INTEGER NOT NULL,
    PRIMARY KEY (POLICY_ID, VERSION, TENANT_ID)
)
/

CREATE TABLE IDN_XACML_POLICY_ATTRIBUTE (
    ID INTEGER NOT NULL,
    ATTRIBUTE_ID VARCHAR(255) NOT NULL,
    ATTRIBUTE_VALUE VARCHAR(255) NOT NULL,
    DATA_TYPE VARCHAR(255) NOT NULL,
    CATEGORY VARCHAR(255) NOT NULL,
    POLICY_ID VARCHAR(255) NOT NULL,
    VERSION INTEGER NOT NULL,
    TENANT_ID INTEGER NOT NULL,
    PRIMARY KEY (ID),
    FOREIGN KEY (POLICY_ID, VERSION, TENANT_ID) REFERENCES IDN_XACML_POLICY (POLICY_ID, VERSION, TENANT_ID) ON DELETE CASCADE
)
/
CREATE SEQUENCE IDN_XACML_POLICY_ATTRIBUTE_SEQ START WITH 1 INCREMENT BY 1 NOCACHE
/
CREATE OR REPLACE TRIGGER IDN_XACML_POLICY_ATTRIBUTE_TRIG
BEFORE INSERT ON IDN_XACML_POLICY_ATTRIBUTE
REFERENCING NEW AS NEW
FOR EACH ROW
    BEGIN
        SELECT IDN_XACML_POLICY_ATTRIBUTE_SEQ.NEXTVAL INTO :NEW.ID FROM dual;
    END;
/

CREATE TABLE IDN_XACML_POLICY_EDITOR_DATA (
    ID INTEGER NOT NULL,
    DATA VARCHAR(500),
    DATA_ORDER INTEGER NOT NULL,
    POLICY_ID VARCHAR(255) NOT NULL,
    VERSION INTEGER NOT NULL,
    TENANT_ID INTEGER NOT NULL,
    PRIMARY KEY (ID),
    FOREIGN KEY (POLICY_ID, VERSION, TENANT_ID) REFERENCES IDN_XACML_POLICY (POLICY_ID, VERSION, TENANT_ID) ON DELETE CASCADE
)
/
CREATE SEQUENCE IDN_XACML_POLICY_EDITOR_DATA_SEQ START WITH 1 INCREMENT BY 1 NOCACHE
/
CREATE OR REPLACE TRIGGER IDN_XACML_POLICY_EDITOR_DATA_TRIG
BEFORE INSERT ON IDN_XACML_POLICY_EDITOR_DATA
REFERENCING NEW AS NEW
FOR EACH ROW
    BEGIN
        SELECT IDN_XACML_POLICY_EDITOR_DATA_SEQ.NEXTVAL INTO :NEW.ID FROM dual;
    END;
/

CREATE TABLE IDN_XACML_POLICY_REFERENCE (
    REFERENCE VARCHAR(255) NOT NULL,
    POLICY_ID VARCHAR(255) NOT NULL,
    VERSION INTEGER NOT NULL,
    TENANT_ID INTEGER NOT NULL,
    PRIMARY KEY (REFERENCE, POLICY_ID, VERSION, TENANT_ID),
    FOREIGN KEY (POLICY_ID, VERSION, TENANT_ID) REFERENCES IDN_XACML_POLICY (POLICY_ID, VERSION, TENANT_ID) ON DELETE CASCADE
)
/

CREATE TABLE IDN_XACML_POLICY_SET_REFERENCE (
    SET_REFERENCE VARCHAR(255) NOT NULL,
    POLICY_ID VARCHAR(255) NOT NULL,
    VERSION INTEGER NOT NULL,
    TENANT_ID INTEGER NOT NULL,
    PRIMARY KEY (SET_REFERENCE, POLICY_ID, VERSION, TENANT_ID),
    FOREIGN KEY (POLICY_ID, VERSION, TENANT_ID) REFERENCES IDN_XACML_POLICY (POLICY_ID, VERSION, TENANT_ID) ON DELETE CASCADE
)
/

CREATE TABLE IDN_XACML_SUBSCRIBER (
    SUBSCRIBER_ID VARCHAR(255) NOT NULL,
    ENTITLEMENT_MODULE_NAME VARCHAR(255) NOT NULL,
    TENANT_ID INTEGER NOT NULL,
    PRIMARY KEY (SUBSCRIBER_ID, TENANT_ID)
)
/

CREATE TABLE IDN_XACML_SUBSCRIBER_PROPERTY (
    PROPERTY_ID VARCHAR(255) NOT NULL,
    DISPLAY_NAME VARCHAR(255) NOT NULL,
    PROPERTY_VALUE VARCHAR(2000) NOT NULL,
    IS_REQUIRED CHAR(1) DEFAULT '0' NOT NULL,
    DISPLAY_ORDER INTEGER NOT NULL,
    IS_SECRET CHAR(1) DEFAULT '0' NOT NULL,
    PROPERTY_MODULE VARCHAR(255),
    SUBSCRIBER_ID VARCHAR(255) NOT NULL,
    TENANT_ID INTEGER NOT NULL,
    PRIMARY KEY (PROPERTY_ID, SUBSCRIBER_ID, TENANT_ID),
    FOREIGN KEY (SUBSCRIBER_ID, TENANT_ID) REFERENCES IDN_XACML_SUBSCRIBER (SUBSCRIBER_ID, TENANT_ID) ON DELETE CASCADE
)
/

CREATE TABLE IDN_XACML_SUBSCRIBER_STATUS (
    ID INTEGER NOT NULL,
    TYPE VARCHAR(255) NOT NULL,
    IS_SUCCESS CHAR(1) DEFAULT '0' NOT NULL,
    USERNAME VARCHAR(255) NOT NULL,
    TARGET VARCHAR(255) NOT NULL,
    TARGET_ACTION VARCHAR(255) NOT NULL,
    LOGGED_AT TIMESTAMP NOT NULL,
    MESSAGE VARCHAR(255),
    SUBSCRIBER_ID VARCHAR(255) NOT NULL,
    TENANT_ID INTEGER NOT NULL,
    PRIMARY KEY (ID),
    FOREIGN KEY (SUBSCRIBER_ID, TENANT_ID) REFERENCES IDN_XACML_SUBSCRIBER (SUBSCRIBER_ID, TENANT_ID) ON DELETE CASCADE
)
/
CREATE SEQUENCE IDN_XACML_SUBSCRIBER_STATUS_SEQ START WITH 1 INCREMENT BY 1 NOCACHE
/
CREATE OR REPLACE TRIGGER IDN_XACML_SUBSCRIBER_STATUS_TRIG
BEFORE INSERT ON IDN_XACML_SUBSCRIBER_STATUS
REFERENCING NEW AS NEW
FOR EACH ROW
    BEGIN
        SELECT IDN_XACML_SUBSCRIBER_STATUS_SEQ.NEXTVAL INTO :NEW.ID FROM dual;
    END;
/

CREATE TABLE IDN_XACML_POLICY_STATUS (
    ID INTEGER NOT NULL,
    TYPE VARCHAR(255) NOT NULL,
    IS_SUCCESS CHAR(1) DEFAULT '0' NOT NULL,
    USERNAME VARCHAR(255) NOT NULL,
    TARGET VARCHAR(255) NOT NULL,
    TARGET_ACTION VARCHAR(255) NOT NULL,
    LOGGED_AT TIMESTAMP NOT NULL,
    MESSAGE VARCHAR(255),
    POLICY_ID VARCHAR(255) NOT NULL,
    POLICY_VERSION INTEGER DEFAULT -1 NOT NULL,
    TENANT_ID INTEGER NOT NULL,
    PRIMARY KEY (ID)
)
/
CREATE SEQUENCE IDN_XACML_POLICY_STATUS_SEQ START WITH 1 INCREMENT BY 1 NOCACHE
/
CREATE OR REPLACE TRIGGER IDN_XACML_POLICY_STATUS_TRIG
BEFORE INSERT ON IDN_XACML_POLICY_STATUS
REFERENCING NEW AS NEW
FOR EACH ROW
    BEGIN
        SELECT IDN_XACML_POLICY_STATUS_SEQ.NEXTVAL INTO :NEW.ID FROM dual;
    END;
/

CREATE TABLE IDN_SAML2_SERVICE_PROVIDER (
    ID INTEGER NOT NULL,
    ISSUER VARCHAR2(255) NOT NULL,
    DEFAULT_ASSERTION_CONSUMER_URL VARCHAR2(2048) NOT NULL,
    NAME_ID_FORMAT VARCHAR2(255) NOT NULL,
    CERT_ALIAS VARCHAR2(255),
    REQ_SIG_VALIDATION CHAR(1),
    SIGN_RESPONSE CHAR(1) NOT NULL,
    SIGN_ASSERTIONS CHAR(1) NOT NULL,
    SIGNING_ALGO VARCHAR2(255) NOT NULL,
    DIGEST_ALGO VARCHAR2(255) NOT NULL,
    ENCRYPT_ASSERTION CHAR(1),
    ASSERTION_ENCRYPTION_ALGO VARCHAR2(255),
    KEY_ENCRYPTION_ALGO VARCHAR2(255),
    ATTR_PROFILE_ENABLED CHAR(1) NOT NULL,
    ATTR_SERVICE_INDEX VARCHAR2(255),
    SLO_PROFILE_ENABLED CHAR(1) NOT NULL,
    SLO_METHOD VARCHAR2(255),
    SLO_RESPONSE_URL VARCHAR2(2048),
    SLO_REQUEST_URL VARCHAR2(2048),
    IDP_INIT_SSO_ENABLED CHAR(1),
    IDP_INIT_SLO_ENABLED CHAR(1),
    QUERY_REQUEST_PROFILE_ENABLED CHAR(1) NOT NULL,
    ECP_ENABLED CHAR(1) NOT NULL,
    ARTIFACT_BINDING_ENABLED CHAR(1) NOT NULL,
    ARTIFACT_RESOLVE_REQ_SIG_VALIDATION CHAR(1),
    IDP_ENTITY_ID_ALIAS VARCHAR2(255),
    ISSUER_QUALIFIER VARCHAR2(255),
    SUPPORTED_ASSERTION_QUERY_REQUEST_TYPES VARCHAR2(255),
    TENANT_ID INTEGER NOT NULL,
    VERSION VARCHAR(15) NOT NULL,
    CREATED_AT TIMESTAMP NOT NULL,
    UPDATED_AT TIMESTAMP NOT NULL,
    ATTR_NAME_FORMAT VARCHAR2(255),
    PRIMARY KEY (ID),
    CONSTRAINT IDN_SAML2_SERVICE_PROVIDER_CONSTRAINT UNIQUE (ISSUER, TENANT_ID)
)
/
CREATE SEQUENCE IDN_SAML2_SERVICE_PROVIDER_SEQ START WITH 1 INCREMENT BY 1 NOCACHE
/
CREATE OR REPLACE TRIGGER IDN_SAML2_SERVICE_PROVIDER_TRIG
            BEFORE INSERT
            ON IDN_SAML2_SERVICE_PROVIDER
            REFERENCING NEW AS NEW
            FOR EACH ROW
                BEGIN
                    SELECT IDN_SAML2_SERVICE_PROVIDER_SEQ.nextval INTO :NEW.ID FROM dual;
                END;
/

CREATE TABLE IDN_SAML2_SP_PROPERTIES (
    ID INTEGER NOT NULL,
    PROPERTY_NAME VARCHAR2(255) NOT NULL,
    PROPERTY_VALUE VARCHAR2(2048) NOT NULL,
    SP_ID INTEGER NOT NULL,
    PRIMARY KEY (ID),
    FOREIGN KEY (SP_ID) REFERENCES IDN_SAML2_SERVICE_PROVIDER(ID) ON DELETE CASCADE
)
/
CREATE SEQUENCE IDN_SAML2_SP_PROPERTIES_SEQ START WITH 1 INCREMENT BY 1 NOCACHE
/
CREATE OR REPLACE TRIGGER IDN_SAML2_SP_PROPERTIES_TRIG
            BEFORE INSERT
            ON IDN_SAML2_SP_PROPERTIES
            REFERENCING NEW AS NEW
            FOR EACH ROW
                BEGIN
                    SELECT IDN_SAML2_SP_PROPERTIES_SEQ.nextval INTO :NEW.ID FROM dual;
                END;
/

CREATE TABLE AUTHORIZATION_DETAILS_TYPES (
    ID CHAR(36) NOT NULL,
    TYPE VARCHAR(255) NOT NULL,
    API_ID CHAR(36) NOT NULL,
    CURSOR_KEY INTEGER NOT NULL,
    NAME VARCHAR(255),
    DESCRIPTION VARCHAR(255),
    JSON_SCHEMA CLOB NOT NULL,
    TENANT_ID INTEGER,
    PRIMARY KEY (ID),
    CONSTRAINT AUTHORIZATION_DETAILS_TYPES_UNIQUE_CONSTRAINT UNIQUE (TYPE, TENANT_ID),
    FOREIGN KEY (API_ID) REFERENCES API_RESOURCE(ID) ON DELETE CASCADE
)
/
CREATE SEQUENCE AUTHORIZATION_DETAILS_TYPES_SEQ START WITH 1 INCREMENT BY 1 NOCACHE
/
CREATE OR REPLACE TRIGGER AUTHORIZATION_DETAILS_TYPES_TRIG
    BEFORE INSERT
    ON AUTHORIZATION_DETAILS_TYPES
    REFERENCING NEW AS NEW
    FOR EACH ROW
        BEGIN
            SELECT AUTHORIZATION_DETAILS_TYPES_SEQ.nextval INTO :NEW.CURSOR_KEY FROM dual;
        END;
/

CREATE TABLE AUTHORIZED_AUTHORIZATION_DETAILS_TYPES (
    APP_ID CHAR(36) NOT NULL,
    API_ID CHAR(36) NOT NULL,
    TYPE_ID CHAR(36) NOT NULL,
    PRIMARY KEY (APP_ID, API_ID, TYPE_ID),
    FOREIGN KEY (API_ID) REFERENCES API_RESOURCE(ID),
    FOREIGN KEY (TYPE_ID) REFERENCES AUTHORIZATION_DETAILS_TYPES(ID) ON DELETE CASCADE,
    FOREIGN KEY (APP_ID) REFERENCES SP_APP(UUID),
    FOREIGN KEY (APP_ID, API_ID) REFERENCES AUTHORIZED_API(APP_ID, API_ID) ON DELETE CASCADE,
    CONSTRAINT AUTHORIZED_AUTHORIZATION_DETAILS_UNIQUE UNIQUE (APP_ID, TYPE_ID)
)
/

CREATE TABLE IDN_OAUTH2_USER_CONSENTED_AUTHORIZATION_DETAILS (
    ID INTEGER NOT NULL,
    CONSENT_ID VARCHAR(255) NOT NULL,
    TYPE_ID CHAR(36) NOT NULL,
    AUTHORIZATION_DETAILS CLOB NOT NULL,
    CONSENT CHAR(1) DEFAULT '0' NOT NULL,
    TENANT_ID INTEGER NOT NULL,
    PRIMARY KEY (ID, CONSENT_ID, TYPE_ID),
    FOREIGN KEY (TYPE_ID) REFERENCES AUTHORIZATION_DETAILS_TYPES(ID) ON DELETE CASCADE,
    FOREIGN KEY (CONSENT_ID) REFERENCES IDN_OAUTH2_USER_CONSENT(CONSENT_ID) ON DELETE CASCADE
)
/
CREATE SEQUENCE IDN_OAUTH2_USER_CONSENTED_AUTHORIZATION_DETAILS_SEQ START WITH 1 INCREMENT BY 1 NOCACHE
/
CREATE OR REPLACE TRIGGER IDN_OAUTH2_USER_CONSENTED_AUTHORIZATION_DETAILS_TRIG
    BEFORE INSERT
    ON IDN_OAUTH2_USER_CONSENTED_AUTHORIZATION_DETAILS
    REFERENCING NEW AS NEW
    FOR EACH ROW
        BEGIN
            SELECT IDN_OAUTH2_USER_CONSENTED_AUTHORIZATION_DETAILS_SEQ.nextval INTO :NEW.ID FROM dual;
        END;
/

CREATE TABLE IDN_OAUTH2_ACCESS_TOKEN_AUTHORIZATION_DETAILS (
    ID INTEGER NOT NULL,
    TYPE_ID CHAR(36) NOT NULL,
    AUTHORIZATION_DETAILS CLOB NOT NULL,
    TOKEN_ID VARCHAR (255),
    TENANT_ID INTEGER DEFAULT -1,
    PRIMARY KEY (ID, TOKEN_ID, TYPE_ID),
    FOREIGN KEY (TYPE_ID) REFERENCES AUTHORIZATION_DETAILS_TYPES(ID) ON DELETE CASCADE,
    FOREIGN KEY (TOKEN_ID) REFERENCES IDN_OAUTH2_ACCESS_TOKEN(TOKEN_ID) ON DELETE CASCADE
)
/
CREATE SEQUENCE IDN_OAUTH2_ACCESS_TOKEN_AUTHORIZATION_DETAILS_SEQ START WITH 1 INCREMENT BY 1 NOCACHE
/
CREATE OR REPLACE TRIGGER IDN_OAUTH2_ACCESS_TOKEN_AUTHORIZATION_DETAILS_TRIG
    BEFORE INSERT
    ON IDN_OAUTH2_ACCESS_TOKEN_AUTHORIZATION_DETAILS
    REFERENCING NEW AS NEW
    FOR EACH ROW
        BEGIN
            SELECT IDN_OAUTH2_ACCESS_TOKEN_AUTHORIZATION_DETAILS_SEQ.nextval INTO :NEW.ID FROM dual;
        END;
/

CREATE TABLE IDN_OAUTH2_AUTHZ_CODE_AUTHORIZATION_DETAILS (
    ID INTEGER NOT NULL,
    TYPE_ID CHAR(36) NOT NULL,
    AUTHORIZATION_DETAILS CLOB NOT NULL,
    CODE_ID VARCHAR(255),
    TENANT_ID INTEGER DEFAULT -1,
    PRIMARY KEY (ID, CODE_ID, TYPE_ID),
    FOREIGN KEY (TYPE_ID) REFERENCES AUTHORIZATION_DETAILS_TYPES(ID) ON DELETE CASCADE,
    FOREIGN KEY (CODE_ID) REFERENCES IDN_OAUTH2_AUTHORIZATION_CODE(CODE_ID) ON DELETE CASCADE
)
/
CREATE SEQUENCE IDN_OAUTH2_AUTHZ_CODE_AUTHORIZATION_DETAILS_SEQ START WITH 1 INCREMENT BY 1 NOCACHE
/
CREATE OR REPLACE TRIGGER IDN_OAUTH2_AUTHZ_CODE_AUTHORIZATION_DETAILS_TRIG
    BEFORE INSERT
    ON IDN_OAUTH2_AUTHZ_CODE_AUTHORIZATION_DETAILS
    REFERENCING NEW AS NEW
    FOR EACH ROW
    BEGIN
        SELECT IDN_OAUTH2_AUTHZ_CODE_AUTHORIZATION_DETAILS_SEQ.nextval INTO :NEW.ID FROM dual;
    END;
/

CREATE TABLE IDN_RULE (
    ID INTEGER,
    UUID CHAR(36) NOT NULL,
    CONTENT BLOB NOT NULL,
    IS_ACTIVE CHAR (1) DEFAULT '1',
    TENANT_ID INTEGER NOT NULL,
    VERSION VARCHAR(15) NOT NULL,
    PRIMARY KEY (ID),
    UNIQUE (UUID)
)
/
CREATE SEQUENCE IDN_RULE_SEQ START WITH 1 INCREMENT BY 1 NOCACHE
/
CREATE OR REPLACE TRIGGER IDN_RULE_TRIGGER
    BEFORE INSERT ON IDN_RULE
    REFERENCING NEW AS NEW FOR EACH ROW
        BEGIN
          SELECT IDN_RULE_SEQ.nextval INTO :NEW.ID FROM dual;
        END;
/
CREATE TABLE IDN_RULE_REFERENCES (
    ID INTEGER,
    RULE_ID INTEGER NOT NULL,
    FIELD_NAME VARCHAR(100) NOT NULL,
    FIELD_REFERENCE VARCHAR(255) NOT NULL,
    TENANT_ID INTEGER NOT NULL,
    PRIMARY KEY (ID),
    FOREIGN KEY (RULE_ID) REFERENCES IDN_RULE(ID) ON DELETE CASCADE
)
/
CREATE SEQUENCE IDN_RULE_REFERENCES_SEQ START WITH 1 INCREMENT BY 1 NOCACHE
/
CREATE OR REPLACE TRIGGER IDN_RULE_REFERENCES_TRIGGER
    BEFORE INSERT ON IDN_RULE_REFERENCES
    REFERENCING NEW AS NEW FOR EACH ROW
        BEGIN
          SELECT IDN_RULE_REFERENCES_SEQ.nextval INTO :NEW.ID FROM dual;
        END;
/
CREATE TABLE IDN_PUSH_DEVICE_STORE (
    ID VARCHAR(255) NOT NULL,
    USER_ID VARCHAR(255) NOT NULL,
    DEVICE_NAME VARCHAR(45) NOT NULL,
    DEVICE_MODEL VARCHAR(45) NOT NULL,
    DEVICE_TOKEN VARCHAR(255) NOT NULL,
    DEVICE_HANDLE VARCHAR(255),
    PUBLIC_KEY VARCHAR(2048) NOT NULL,
    PROVIDER VARCHAR(45) NOT NULL,
    TENANT_ID INTEGER NOT NULL,
    PRIMARY KEY (ID),
    UNIQUE (USER_ID)
)
/
CREATE TABLE MIGRATION_STATUS (
    IS_VERSION VARCHAR(255) NOT NULL,
    STATUS VARCHAR(255),
    LOCKED_BY VARCHAR(255),
    LOCK_ACQUIRED_AT TIMESTAMP,
    EXPIRES_AT TIMESTAMP,
    PRIMARY KEY (IS_VERSION)
)
/

ALTER TABLE IDP_AUTHENTICATOR ADD DEFINED_BY VARCHAR(25) DEFAULT 'SYSTEM' NOT NULL
/
ALTER TABLE IDP_AUTHENTICATOR ADD AUTHENTICATION_TYPE VARCHAR(25) NOT NULL DEFAULT 'IDENTIFICATION'
/
ALTER TABLE IDP_AUTHENTICATOR ADD IMAGE_URL VARCHAR(1024)
/
ALTER TABLE IDP_AUTHENTICATOR ADD DESCRIPTION VARCHAR(1024)
/
ALTER TABLE SP_APP ADD VERSION VARCHAR(255) NOT NULL DEFAULT 'v1.0.0'
/
ALTER TABLE IDN_CERTIFICATE ADD UUID CHAR(36)
/

INSERT ALL INTO IDN_SECRET_TYPE (ID, NAME, DESCRIPTION) VALUES
('33f0a41b-569d-4ea5-a891-6c0e78a1c3b0', 'ACTION_API_ENDPOINT_AUTH_SECRETS', 'Secret type to uniquely identify secrets relevant to action endpoint authentication properties')
INTO IDN_SECRET_TYPE (ID, NAME, DESCRIPTION) VALUES
('b411dafd-e2c4-4d2f-afba-3900d802725a', 'PUSH_PROVIDER_SECRET_PROPERTIES', 'Secret type to uniquely identify secrets relevant to push provider properties')
SELECT 1 FROM dual
/

INSERT INTO IDN_CONFIG_TYPE (ID, NAME, DESCRIPTION)
SELECT '3e5b1f91-72d8-4fbc-94d1-1b9a4f8c3b07', 'IMPERSONATION_CONFIGURATION', 'A resource type to keep the tenant impersonation preferences.' FROM DUAL
WHERE NOT EXISTS (SELECT * FROM IDN_CONFIG_TYPE WHERE id = '3e5b1f91-72d8-4fbc-94d1-1b9a4f8c3b07' OR name = 'IMPERSONATION_CONFIGURATION')
/

INSERT ALL INTO IDN_CONFIG_TYPE (ID, NAME, DESCRIPTION) VALUES
('91116e95-ca63-4787-be2d-de13d04d1b55', 'CERTIFICATE_VALIDATOR', 'A resource type to keep the certificate validators.')
INTO IDN_CONFIG_TYPE (ID, NAME, DESCRIPTION) VALUES
('a17952b9-0942-4669-8529-479ca481146b', 'CERTIFICATE_REVOCATION_VALIDATION_CA', 'A resource type to keep the certificate revocation validation related certificate authorities.')
INTO IDN_CONFIG_TYPE (ID, NAME, DESCRIPTION) VALUES
('32360745-9c3e-4391-b563-66f17f0eb93a', 'ADMIN_ADVISORY_BANNER', 'A resource type to store admin advisory banner configurations.')
INTO IDN_CONFIG_TYPE (ID, NAME, DESCRIPTION) VALUES
('82ab7001-fb0e-44da-9169-1f63e4964d9b', 'REMOTE_LOGGING_CONFIG', 'A resource type to store remote server logger configurations.')
SELECT 1 FROM dual
/

INSERT INTO MIGRATION_STATUS (is_version, locked_by, status, lock_acquired_at, expires_at) values ('7.1.0', NULL, 'NOT-STARTED', NULL, NULL)
/

ALTER TABLE IDN_OAUTH2_ACCESS_TOKEN_AUDIT ADD TOKEN_BINDING_REF VARCHAR2(32) DEFAULT 'NONE'
/
ALTER TABLE IDN_OAUTH2_ACCESS_TOKEN_AUDIT ADD CONSENTED_TOKEN VARCHAR(6)
/
ALTER TABLE IDN_OAUTH2_ACCESS_TOKEN_AUDIT ADD AUTHORIZED_ORGANIZATION varchar(36) DEFAULT('NONE') NOT NULL
/
-- --------------------------- INDEX CREATION -----------------------------

-- ACTIONS --
CREATE INDEX IDX_IDN_ACTION_TY_TI ON IDN_ACTION (TYPE, TENANT_ID)
/
CREATE INDEX IDX_IDN_ACTION_PROPERTIES_AU_TI ON IDN_ACTION_PROPERTIES (ACTION_UUID, TENANT_ID)
/

-- XACML --
CREATE INDEX IDX_POLICY_ATTRIBUTE ON IDN_XACML_POLICY_ATTRIBUTE (POLICY_ID, VERSION, TENANT_ID)
/
CREATE INDEX IDX_POLICY_EDITOR_DATA_FK ON IDN_XACML_POLICY_EDITOR_DATA (POLICY_ID, VERSION, TENANT_ID)
/
CREATE INDEX IDX_POLICY_REF ON IDN_XACML_POLICY_REFERENCE (POLICY_ID, VERSION, TENANT_ID)
/
CREATE INDEX IDX_POLICY_SET_REF ON IDN_XACML_POLICY_SET_REFERENCE (POLICY_ID, VERSION, TENANT_ID)
/
CREATE INDEX IDX_SUBSCRIBER_PROPERTY ON IDN_XACML_SUBSCRIBER_PROPERTY (SUBSCRIBER_ID, TENANT_ID)
/
CREATE INDEX IDX_XACML_SUBSCRIBER_STATUS ON IDN_XACML_SUBSCRIBER_STATUS (SUBSCRIBER_ID, TENANT_ID)
/
CREATE INDEX IDX_XACML_POLICY_STATUS ON IDN_XACML_POLICY_STATUS (POLICY_ID, POLICY_VERSION, TENANT_ID)
/

-- SAML --
CREATE INDEX IDX_SAML2_SP_TENANT_ID ON IDN_SAML2_SERVICE_PROVIDER (TENANT_ID)
/
CREATE INDEX IDX_SAML2_SP_PROPERTIES ON IDN_SAML2_SP_PROPERTIES (SP_ID)
/

-- RULES --
CREATE INDEX IDX_IDN_RULE_UUID_TID ON IDN_RULE (UUID, TENANT_ID)
/
CREATE INDEX IDX_IDN_RULE_REF_RID_TID ON IDN_RULE_REFERENCES (RULE_ID, TENANT_ID)
/

-- SP_CLAIM_MAPPING --
CREATE INDEX IDX_SPCM_APP ON SP_CLAIM_MAPPING (APP_ID)
/

-- IDP_AUTHENTICATOR --
CREATE INDEX IDX_IDP_AUTH_DEFINED_BY ON IDP_AUTHENTICATOR (DEFINED_BY)
/
CREATE INDEX IDX_IDP_AUTH_IDP_ID ON IDP_AUTHENTICATOR (IDP_ID)
/
