text: CREATE TABLE IF NOT EXISTS IDN_BASE_TABLE (
    PRODUCT_NAME VARCHAR(20),
    PRIMARY KEY (PRODUCT_NAME)
  )
    ENGINE NDB;
  
  INSERT INTO IDN_BASE_TABLE VALUES ('WSO2 Identity Server');
  
  CREATE TABLE IF NOT EXISTS IDN_OAUTH_CONSUMER_APPS (
    ID                            INTEGER NOT NULL AUTO_INCREMENT,
    CONSUMER_KEY                  VARCHAR(255),
    CONSUMER_SECRET               VARCHAR(2048),
    USERNAME                      VARCHAR(255),
    TENANT_ID                     INTEGER          DEFAULT 0,
    USER_DOMAIN                   VARCHAR(50),
    APP_NAME                      VARCHAR(255),
    OAUTH_VERSION                 VARCHAR(128),
    CALLBACK_URL                  VARCHAR(1024),
    GRANT_TYPES                   VARCHAR(1024),
    PKCE_MANDATORY                CHAR(1)          DEFAULT '0',
    PKCE_SUPPORT_PLAIN            CHAR(1)          DEFAULT '0',
    APP_STATE                     VARCHAR(25)      DEFAULT 'ACTIVE',
    USER_ACCESS_TOKEN_EXPIRE_TIME BIGINT           DEFAULT 3600,
    APP_ACCESS_TOKEN_EXPIRE_TIME  BIGINT           DEFAULT 3600,
    REFRESH_TOKEN_EXPIRE_TIME     BIGINT           DEFAULT 84600,
    ID_TOKEN_EXPIRE_TIME          BIGINT           DEFAULT 3600,
    CONSTRAINT CONSUMER_KEY_CONSTRAINT UNIQUE (CONSUMER_KEY),
    PRIMARY KEY (ID)
  )
    ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS IDN_OAUTH2_SCOPE_VALIDATORS (
    APP_ID          INTEGER      NOT NULL,
    SCOPE_VALIDATOR VARCHAR(128) NOT NULL,
    PRIMARY KEY (APP_ID, SCOPE_VALIDATOR),
    FOREIGN KEY (APP_ID) REFERENCES IDN_OAUTH_CONSUMER_APPS (ID)
      ON DELETE CASCADE
  )
    ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS IDN_OAUTH1A_REQUEST_TOKEN (
    REQUEST_TOKEN        VARCHAR(255),
    REQUEST_TOKEN_SECRET VARCHAR(512),
    CONSUMER_KEY_ID      INTEGER,
    CALLBACK_URL         VARCHAR(1024),
    SCOPE                VARCHAR(2048),
    AUTHORIZED           VARCHAR(128),
    OAUTH_VERIFIER       VARCHAR(512),
    AUTHZ_USER           VARCHAR(512),
    TENANT_ID            INTEGER DEFAULT -1,
    PRIMARY KEY (REQUEST_TOKEN),
    FOREIGN KEY (CONSUMER_KEY_ID) REFERENCES IDN_OAUTH_CONSUMER_APPS (ID)
      ON DELETE CASCADE
  )
    ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS IDN_OAUTH1A_ACCESS_TOKEN (
    ACCESS_TOKEN        VARCHAR(255),
    ACCESS_TOKEN_SECRET VARCHAR(512),
    CONSUMER_KEY_ID     INTEGER,
    SCOPE               VARCHAR(2048),
    AUTHZ_USER          VARCHAR(512),
    TENANT_ID           INTEGER DEFAULT -1,
    PRIMARY KEY (ACCESS_TOKEN),
    FOREIGN KEY (CONSUMER_KEY_ID) REFERENCES IDN_OAUTH_CONSUMER_APPS (ID)
      ON DELETE CASCADE
  )
    ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS IDN_OAUTH2_ACCESS_TOKEN (
    TOKEN_ID                      VARCHAR(255),
    ACCESS_TOKEN                  VARCHAR(2048),
    REFRESH_TOKEN                 VARCHAR(2048),
    CONSUMER_KEY_ID               INTEGER,
    AUTHZ_USER                    VARCHAR(100),
    TENANT_ID                     INTEGER,
    USER_DOMAIN                   VARCHAR(50),
    USER_TYPE                     VARCHAR(25),
    GRANT_TYPE                    VARCHAR(50),
    TIME_CREATED                  TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    REFRESH_TOKEN_TIME_CREATED    TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    VALIDITY_PERIOD               BIGINT,
    REFRESH_TOKEN_VALIDITY_PERIOD BIGINT,
    TOKEN_SCOPE_HASH              VARCHAR(32),
    TOKEN_STATE                   VARCHAR(25)        DEFAULT 'ACTIVE',
    TOKEN_STATE_ID                VARCHAR(128)       DEFAULT 'NONE',
    SUBJECT_IDENTIFIER            VARCHAR(255),
    ACCESS_TOKEN_HASH             VARCHAR(512),
    REFRESH_TOKEN_HASH            VARCHAR(512),
    IDP_ID                        INTEGER DEFAULT -1 NOT NULL,
    TOKEN_BINDING_REF             VARCHAR(32) DEFAULT 'NONE',
    PRIMARY KEY (TOKEN_ID),
    FOREIGN KEY (CONSUMER_KEY_ID) REFERENCES IDN_OAUTH_CONSUMER_APPS (ID)
      ON DELETE CASCADE,
    CONSTRAINT CON_APP_KEY UNIQUE (CONSUMER_KEY_ID, AUTHZ_USER, TENANT_ID, USER_DOMAIN, USER_TYPE, TOKEN_SCOPE_HASH,
                                   TOKEN_STATE, TOKEN_STATE_ID, IDP_ID, TOKEN_BINDING_REF)
  )
    ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS IDN_OAUTH2_TOKEN_BINDING (
    TOKEN_ID                       VARCHAR(255),
    TOKEN_BINDING_TYPE             VARCHAR(32),
    TOKEN_BINDING_REF              VARCHAR(32),
    TOKEN_BINDING_VALUE            VARCHAR(1024),
    TENANT_ID                      INTEGER DEFAULT -1,
    UNIQUE (TOKEN_ID,TOKEN_BINDING_TYPE,TOKEN_BINDING_VALUE),
    PRIMARY KEY (TOKEN_ID),
    FOREIGN KEY (TOKEN_ID) REFERENCES IDN_OAUTH2_ACCESS_TOKEN(TOKEN_ID) ON DELETE CASCADE
  )
    ENGINE NDB;
  
  
  CREATE TABLE IF NOT EXISTS IDN_OAUTH2_ACCESS_TOKEN_AUDIT (
    ID                            INTEGER NOT NULL AUTO_INCREMENT,
    TOKEN_ID                      VARCHAR(255),
    ACCESS_TOKEN                  VARCHAR(2048),
    REFRESH_TOKEN                 VARCHAR(2048),
    CONSUMER_KEY_ID               INTEGER,
    AUTHZ_USER                    VARCHAR(100),
    TENANT_ID                     INTEGER,
    USER_DOMAIN                   VARCHAR(50),
    USER_TYPE                     VARCHAR(25),
    GRANT_TYPE                    VARCHAR(50),
    TIME_CREATED                  TIMESTAMP NULL,
    REFRESH_TOKEN_TIME_CREATED    TIMESTAMP NULL,
    VALIDITY_PERIOD               BIGINT,
    REFRESH_TOKEN_VALIDITY_PERIOD BIGINT,
    TOKEN_SCOPE_HASH              VARCHAR(32),
    TOKEN_STATE                   VARCHAR(25),
    TOKEN_STATE_ID                VARCHAR(128),
    SUBJECT_IDENTIFIER            VARCHAR(255),
    ACCESS_TOKEN_HASH             VARCHAR(512),
    REFRESH_TOKEN_HASH            VARCHAR(512),
    INVALIDATED_TIME              TIMESTAMP NULL,
    IDP_ID                        INTEGER DEFAULT -1 NOT NULL,
    PRIMARY KEY(ID)
  );
  
  CREATE TABLE IF NOT EXISTS IDN_OAUTH2_AUTHORIZATION_CODE (
    CODE_ID                    VARCHAR(255),
    AUTHORIZATION_CODE         VARCHAR(2048),
    CONSUMER_KEY_ID            INTEGER,
    CALLBACK_URL               VARCHAR(1024),
    SCOPE                      VARCHAR(2048),
    AUTHZ_USER                 VARCHAR(100),
    TENANT_ID                  INTEGER,
    USER_DOMAIN                VARCHAR(50),
    TIME_CREATED               TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    VALIDITY_PERIOD            BIGINT,
    STATE                      VARCHAR(25) DEFAULT 'ACTIVE',
    TOKEN_ID                   VARCHAR(255),
    SUBJECT_IDENTIFIER         VARCHAR(255),
    PKCE_CODE_CHALLENGE        VARCHAR(255),
    PKCE_CODE_CHALLENGE_METHOD VARCHAR(128),
    AUTHORIZATION_CODE_HASH    VARCHAR(512),
    IDP_ID                     INTEGER DEFAULT -1 NOT NULL,
    PRIMARY KEY (CODE_ID),
    FOREIGN KEY (CONSUMER_KEY_ID) REFERENCES IDN_OAUTH_CONSUMER_APPS (ID)
      ON DELETE CASCADE
  )
    ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS IDN_OAUTH2_AUTHZ_CODE_SCOPE(
     CODE_ID   VARCHAR(255),
     SCOPE     VARCHAR(60),
     TENANT_ID INTEGER DEFAULT -1,
     PRIMARY KEY (CODE_ID, SCOPE),
     FOREIGN KEY (CODE_ID) REFERENCES IDN_OAUTH2_AUTHORIZATION_CODE (CODE_ID)
      ON DELETE CASCADE
  )
     ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS IDN_OAUTH2_DEVICE_FLOW (
      CODE_ID VARCHAR(255),
      DEVICE_CODE VARCHAR(255),
      USER_CODE VARCHAR(25),
      QUANTIFIER INTEGER NOT NULL DEFAULT 0,
      CONSUMER_KEY_ID INTEGER,
      LAST_POLL_TIME TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
      EXPIRY_TIME TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
      TIME_CREATED TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
      POLL_TIME BIGINT,
      STATUS VARCHAR (25) DEFAULT 'PENDING',
      AUTHZ_USER VARCHAR (100),
      TENANT_ID INTEGER,
      USER_DOMAIN VARCHAR(50),
      IDP_ID INTEGER,
      PRIMARY KEY (DEVICE_CODE),
      UNIQUE (CODE_ID),
      CONSTRAINT USRCDE_QNTFR_CONSTRAINT UNIQUE (USER_CODE, QUANTIFIER),
      FOREIGN KEY (CONSUMER_KEY_ID) REFERENCES IDN_OAUTH_CONSUMER_APPS(ID) ON DELETE CASCADE
  )
      ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS IDN_OAUTH2_DEVICE_FLOW_SCOPES (
      ID INTEGER NOT NULL AUTO_INCREMENT,
      SCOPE_ID VARCHAR(255),
      SCOPE VARCHAR(255),
      PRIMARY KEY (ID),
      FOREIGN KEY (SCOPE_ID) REFERENCES IDN_OAUTH2_DEVICE_FLOW(CODE_ID) ON DELETE CASCADE
  )
      ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS IDN_OAUTH2_ACCESS_TOKEN_SCOPE (
    TOKEN_ID    VARCHAR(255),
    TOKEN_SCOPE VARCHAR(60),
    TENANT_ID   INTEGER DEFAULT -1,
    PRIMARY KEY (TOKEN_ID, TOKEN_SCOPE),
    FOREIGN KEY (TOKEN_ID) REFERENCES IDN_OAUTH2_ACCESS_TOKEN (TOKEN_ID)
      ON DELETE CASCADE
  )
    ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS IDN_OAUTH2_SCOPE (
    SCOPE_ID     INTEGER      NOT NULL AUTO_INCREMENT,
    NAME         VARCHAR(255) NOT NULL,
    DISPLAY_NAME VARCHAR(255) NOT NULL,
    DESCRIPTION  VARCHAR(512),
    TENANT_ID    INTEGER      NOT NULL DEFAULT -1,
    SCOPE_TYPE   VARCHAR(255) NOT NULL,
    PRIMARY KEY (SCOPE_ID),
    UNIQUE (NAME, TENANT_ID)
  )
    ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS IDN_OAUTH2_SCOPE_BINDING (
    ID            INTEGER NOT NULL AUTO_INCREMENT,
    SCOPE_ID      INTEGER NOT NULL,
    SCOPE_BINDING VARCHAR(255) NOT NULL,
    BINDING_TYPE VARCHAR(255) NOT NULL,
    FOREIGN KEY (SCOPE_ID) REFERENCES IDN_OAUTH2_SCOPE (SCOPE_ID)
      ON DELETE CASCADE,
    UNIQUE (SCOPE_ID, SCOPE_BINDING, BINDING_TYPE),
    PRIMARY KEY (ID)
  )
    ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS IDN_OAUTH2_RESOURCE_SCOPE (
    RESOURCE_PATH VARCHAR(255) NOT NULL,
    SCOPE_ID      INTEGER      NOT NULL,
    TENANT_ID     INTEGER DEFAULT -1,
    PRIMARY KEY (RESOURCE_PATH),
    FOREIGN KEY (SCOPE_ID) REFERENCES IDN_OAUTH2_SCOPE (SCOPE_ID)
      ON DELETE CASCADE
  )
    ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS IDN_SCIM_GROUP (
    ID         INTEGER AUTO_INCREMENT,
    TENANT_ID  INTEGER       NOT NULL,
    ROLE_NAME  VARCHAR(255)  NOT NULL,
    ATTR_NAME  VARCHAR(1024) NOT NULL,
    ATTR_VALUE VARCHAR(1024),
    UNIQUE(TENANT_ID, ROLE_NAME, ATTR_NAME),
    PRIMARY KEY (ID)
  )
    ENGINE NDB;
  
  
  CREATE TABLE IF NOT EXISTS IDN_OPENID_REMEMBER_ME (
    USER_NAME    VARCHAR(255) NOT NULL,
    TENANT_ID    INTEGER DEFAULT 0,
    COOKIE_VALUE VARCHAR(1024),
    CREATED_TIME TIMESTAMP,
    PRIMARY KEY (USER_NAME, TENANT_ID)
  )
    ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS IDN_OPENID_USER_RPS (
    USER_NAME            VARCHAR(255) NOT NULL,
    TENANT_ID            INTEGER      DEFAULT 0,
    RP_URL               VARCHAR(255) NOT NULL,
    TRUSTED_ALWAYS       VARCHAR(128) DEFAULT 'FALSE',
    LAST_VISIT           DATE         NOT NULL,
    VISIT_COUNT          INTEGER      DEFAULT 0,
    DEFAULT_PROFILE_NAME VARCHAR(255) DEFAULT 'DEFAULT',
    PRIMARY KEY (USER_NAME, TENANT_ID, RP_URL)
  )
    ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS IDN_OPENID_ASSOCIATIONS (
    HANDLE      VARCHAR(255) NOT NULL,
    ASSOC_TYPE  VARCHAR(255) NOT NULL,
    EXPIRE_IN   TIMESTAMP    NOT NULL,
    MAC_KEY     VARCHAR(255) NOT NULL,
    ASSOC_STORE VARCHAR(128) DEFAULT 'SHARED',
    TENANT_ID   INTEGER      DEFAULT -1,
    PRIMARY KEY (HANDLE)
  )
    ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS IDN_STS_STORE (
    ID            INTEGER               AUTO_INCREMENT,
    TOKEN_ID      VARCHAR(255) NOT NULL,
    TOKEN_CONTENT BLOB(1024)   NOT NULL,
    CREATE_DATE   TIMESTAMP    NOT NULL,
    EXPIRE_DATE   TIMESTAMP    NOT NULL DEFAULT CURRENT_TIMESTAMP,
    STATE         INTEGER               DEFAULT 0,
    PRIMARY KEY (ID)
  )
    ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS IDN_IDENTITY_USER_DATA (
    TENANT_ID  INTEGER DEFAULT -1234,
    USER_NAME  VARCHAR(255) NOT NULL,
    DATA_KEY   VARCHAR(255) NOT NULL,
    DATA_VALUE VARCHAR(2048),
    PRIMARY KEY (TENANT_ID, USER_NAME, DATA_KEY)
  )
    ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS IDN_IDENTITY_META_DATA (
    USER_NAME     VARCHAR(255) NOT NULL,
    TENANT_ID     INTEGER DEFAULT -1234,
    METADATA_TYPE VARCHAR(255) NOT NULL,
    METADATA      VARCHAR(255) NOT NULL,
    VALID         VARCHAR(255) NOT NULL,
    PRIMARY KEY (TENANT_ID, USER_NAME, METADATA_TYPE, METADATA)
  )
    ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS IDN_THRIFT_SESSION (
    SESSION_ID         VARCHAR(255) NOT NULL,
    USER_NAME          VARCHAR(255) NOT NULL,
    CREATED_TIME       VARCHAR(255) NOT NULL,
    LAST_MODIFIED_TIME VARCHAR(255) NOT NULL,
    TENANT_ID          INTEGER DEFAULT -1,
    PRIMARY KEY (SESSION_ID)
  )
    ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS IDN_AUTH_SESSION_STORE (
    SESSION_ID     VARCHAR(100) NOT NULL,
    SESSION_TYPE   VARCHAR(100) NOT NULL,
    OPERATION      VARCHAR(10)  NOT NULL,
    SESSION_OBJECT BLOB,
    TIME_CREATED   BIGINT,
    TENANT_ID      INTEGER DEFAULT -1,
    EXPIRY_TIME    BIGINT,
    PRIMARY KEY (SESSION_ID, SESSION_TYPE, TIME_CREATED, OPERATION)
  )
    ENGINE NDB;
  
  
  CREATE TABLE IF NOT EXISTS IDN_AUTH_TEMP_SESSION_STORE (
    SESSION_ID     VARCHAR(100) NOT NULL,
    SESSION_TYPE   VARCHAR(100) NOT NULL,
    OPERATION      VARCHAR(10)  NOT NULL,
    SESSION_OBJECT BLOB,
    TIME_CREATED   BIGINT,
    TENANT_ID      INTEGER DEFAULT -1,
    EXPIRY_TIME    BIGINT,
    PRIMARY KEY (SESSION_ID, SESSION_TYPE, TIME_CREATED, OPERATION)
  )
    ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS IDN_AUTH_USER (
    USER_ID VARCHAR(255) NOT NULL,
    USER_NAME VARCHAR(255) NOT NULL,
    TENANT_ID INTEGER NOT NULL,
    DOMAIN_NAME VARCHAR(255) NOT NULL,
    IDP_ID INTEGER NOT NULL,
    PRIMARY KEY (USER_ID),
    CONSTRAINT USER_STORE_CONSTRAINT UNIQUE (USER_NAME, TENANT_ID, DOMAIN_NAME, IDP_ID)
  )
    ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS IDN_AUTH_USER_SESSION_MAPPING (
    ID INTEGER NOT NULL AUTO_INCREMENT,
    USER_ID VARCHAR(255) NOT NULL,
    SESSION_ID VARCHAR(255) NOT NULL,
    CONSTRAINT USER_SESSION_STORE_CONSTRAINT UNIQUE (USER_ID, SESSION_ID),
    PRIMARY KEY (ID)
  )
    ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS IDN_AUTH_SESSION_APP_INFO (
    SESSION_ID VARCHAR (100) NOT NULL,
    SUBJECT VARCHAR (100) NOT NULL,
    APP_ID INTEGER NOT NULL,
    INBOUND_AUTH_TYPE VARCHAR (255) NOT NULL,
    PRIMARY KEY (SESSION_ID, SUBJECT, APP_ID, INBOUND_AUTH_TYPE)
  )
    ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS IDN_AUTH_SESSION_META_DATA (
    SESSION_ID VARCHAR (100) NOT NULL,
    PROPERTY_TYPE VARCHAR (100) NOT NULL,
    VALUE VARCHAR (255) NOT NULL,
    PRIMARY KEY (SESSION_ID, PROPERTY_TYPE, VALUE)
  )
    ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS SP_APP (
    ID                            INTEGER      NOT NULL AUTO_INCREMENT,
    TENANT_ID                     INTEGER      NOT NULL,
    APP_NAME                      VARCHAR(255) NOT NULL,
    USER_STORE                    VARCHAR(255) NOT NULL,
    USERNAME                      VARCHAR(255) NOT NULL,
    DESCRIPTION                   VARCHAR(1024),
    ROLE_CLAIM                    VARCHAR(512),
    AUTH_TYPE                     VARCHAR(255) NOT NULL,
    PROVISIONING_USERSTORE_DOMAIN VARCHAR(512),
    IS_LOCAL_CLAIM_DIALECT        CHAR(1)               DEFAULT '1',
    IS_SEND_LOCAL_SUBJECT_ID      CHAR(1)               DEFAULT '0',
    IS_SEND_AUTH_LIST_OF_IDPS     CHAR(1)               DEFAULT '0',
    IS_USE_TENANT_DOMAIN_SUBJECT  CHAR(1)               DEFAULT '1',
    IS_USE_USER_DOMAIN_SUBJECT    CHAR(1)               DEFAULT '1',
    ENABLE_AUTHORIZATION          CHAR(1)               DEFAULT '0',
    SUBJECT_CLAIM_URI             VARCHAR(512),
    IS_SAAS_APP                   CHAR(1)               DEFAULT '0',
    IS_DUMB_MODE                  CHAR(1)               DEFAULT '0',
    UUID                          CHAR(36),
    IMAGE_URL                     VARCHAR(1024),
    ACCESS_URL                     VARCHAR(1024),
    IS_DISCOVERABLE               CHAR(1)               DEFAULT '0',
  
    PRIMARY KEY (ID)
  )
    ENGINE NDB;
  
  ALTER TABLE SP_APP
    ADD CONSTRAINT APPLICATION_NAME_CONSTRAINT UNIQUE (APP_NAME, TENANT_ID);
  
  ALTER TABLE SP_APP
    ADD CONSTRAINT APPLICATION_UUID_CONSTRAINT UNIQUE (UUID);
  
  CREATE TABLE IF NOT EXISTS SP_METADATA (
    ID           INTEGER AUTO_INCREMENT,
    SP_ID        INTEGER,
    NAME         VARCHAR(255) NOT NULL,
    VALUE        VARCHAR(255) NOT NULL,
    DISPLAY_NAME VARCHAR(255),
    TENANT_ID    INTEGER DEFAULT -1,
    PRIMARY KEY (ID),
    CONSTRAINT SP_METADATA_CONSTRAINT UNIQUE (SP_ID, NAME),
    FOREIGN KEY (SP_ID) REFERENCES SP_APP (ID)
      ON DELETE CASCADE
  )
    ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS SP_INBOUND_AUTH (
    ID                  INTEGER      NOT NULL AUTO_INCREMENT,
    TENANT_ID           INTEGER      NOT NULL,
    INBOUND_AUTH_KEY    VARCHAR(255),
    INBOUND_AUTH_TYPE   VARCHAR(255) NOT NULL,
    INBOUND_CONFIG_TYPE VARCHAR(255) NOT NULL,
    PROP_NAME           VARCHAR(255),
    PROP_VALUE          VARCHAR(1024),
    APP_ID              INTEGER      NOT NULL,
    PRIMARY KEY (ID)
  )
    ENGINE NDB;
  
  ALTER TABLE SP_INBOUND_AUTH
    ADD CONSTRAINT APPLICATION_ID_CONSTRAINT FOREIGN KEY (APP_ID) REFERENCES SP_APP (ID)
    ON DELETE CASCADE;
  
  CREATE TABLE IF NOT EXISTS SP_AUTH_STEP (
    ID                INTEGER NOT NULL AUTO_INCREMENT,
    TENANT_ID         INTEGER NOT NULL,
    STEP_ORDER        INTEGER          DEFAULT 1,
    APP_ID            INTEGER NOT NULL,
    IS_SUBJECT_STEP   CHAR(1)          DEFAULT '0',
    IS_ATTRIBUTE_STEP CHAR(1)          DEFAULT '0',
    PRIMARY KEY (ID)
  )
    ENGINE NDB;
  
  ALTER TABLE SP_AUTH_STEP
    ADD CONSTRAINT APPLICATION_ID_CONSTRAINT_STEP FOREIGN KEY (APP_ID) REFERENCES SP_APP (ID)
    ON DELETE CASCADE;
  
  CREATE TABLE IF NOT EXISTS SP_FEDERATED_IDP (
    ID               INTEGER NOT NULL,
    TENANT_ID        INTEGER NOT NULL,
    AUTHENTICATOR_ID INTEGER NOT NULL,
    PRIMARY KEY (ID, AUTHENTICATOR_ID)
  )
    ENGINE NDB;
  
  ALTER TABLE SP_FEDERATED_IDP
    ADD CONSTRAINT STEP_ID_CONSTRAINT FOREIGN KEY (ID) REFERENCES SP_AUTH_STEP (ID)
    ON DELETE CASCADE;
  
  CREATE TABLE IF NOT EXISTS SP_CLAIM_DIALECT (
    ID         INTEGER      NOT NULL AUTO_INCREMENT,
    TENANT_ID  INTEGER      NOT NULL,
    SP_DIALECT VARCHAR(512) NOT NULL,
    APP_ID     INTEGER      NOT NULL,
    PRIMARY KEY (ID)
  )
    ENGINE NDB;
  
  ALTER TABLE SP_CLAIM_DIALECT
    ADD CONSTRAINT DIALECTID_APPID_CONSTRAINT FOREIGN KEY (APP_ID) REFERENCES SP_APP (ID)
    ON DELETE CASCADE;
  
  CREATE TABLE IF NOT EXISTS SP_CLAIM_MAPPING (
    ID            INTEGER      NOT NULL AUTO_INCREMENT,
    TENANT_ID     INTEGER      NOT NULL,
    IDP_CLAIM     VARCHAR(512) NOT NULL,
    SP_CLAIM      VARCHAR(512) NOT NULL,
    APP_ID        INTEGER      NOT NULL,
    IS_REQUESTED  VARCHAR(128)          DEFAULT '0',
    IS_MANDATORY  VARCHAR(128)          DEFAULT '0',
    DEFAULT_VALUE VARCHAR(255),
    PRIMARY KEY (ID)
  )
    ENGINE NDB;
  
  ALTER TABLE SP_CLAIM_MAPPING
    ADD CONSTRAINT CLAIMID_APPID_CONSTRAINT FOREIGN KEY (APP_ID) REFERENCES SP_APP (ID)
    ON DELETE CASCADE;
  
  CREATE TABLE IF NOT EXISTS SP_ROLE_MAPPING (
    ID        INTEGER      NOT NULL AUTO_INCREMENT,
    TENANT_ID INTEGER      NOT NULL,
    IDP_ROLE  VARCHAR(255) NOT NULL,
    SP_ROLE   VARCHAR(255) NOT NULL,
    APP_ID    INTEGER      NOT NULL,
    PRIMARY KEY (ID)
  )
    ENGINE NDB;
  
  ALTER TABLE SP_ROLE_MAPPING
    ADD CONSTRAINT ROLEID_APPID_CONSTRAINT FOREIGN KEY (APP_ID) REFERENCES SP_APP (ID)
    ON DELETE CASCADE;
  
  CREATE TABLE IF NOT EXISTS SP_REQ_PATH_AUTHENTICATOR (
    ID                 INTEGER      NOT NULL AUTO_INCREMENT,
    TENANT_ID          INTEGER      NOT NULL,
    AUTHENTICATOR_NAME VARCHAR(255) NOT NULL,
    APP_ID             INTEGER      NOT NULL,
    PRIMARY KEY (ID)
  )
    ENGINE NDB;
  
  ALTER TABLE SP_REQ_PATH_AUTHENTICATOR
    ADD CONSTRAINT REQ_AUTH_APPID_CONSTRAINT FOREIGN KEY (APP_ID) REFERENCES SP_APP (ID)
    ON DELETE CASCADE;
  
  CREATE TABLE IF NOT EXISTS SP_PROVISIONING_CONNECTOR (
    ID             INTEGER      NOT NULL AUTO_INCREMENT,
    TENANT_ID      INTEGER      NOT NULL,
    IDP_NAME       VARCHAR(255) NOT NULL,
    CONNECTOR_NAME VARCHAR(255) NOT NULL,
    APP_ID         INTEGER      NOT NULL,
    IS_JIT_ENABLED CHAR(1)      NOT NULL DEFAULT '0',
    BLOCKING       CHAR(1)      NOT NULL DEFAULT '0',
    RULE_ENABLED   CHAR(1)      NOT NULL DEFAULT '0',
    PRIMARY KEY (ID)
  )
    ENGINE NDB;
  
  ALTER TABLE SP_PROVISIONING_CONNECTOR
    ADD CONSTRAINT PRO_CONNECTOR_APPID_CONSTRAINT FOREIGN KEY (APP_ID) REFERENCES SP_APP (ID)
    ON DELETE CASCADE;
  
  CREATE TABLE SP_AUTH_SCRIPT (
    ID         INTEGER AUTO_INCREMENT NOT NULL,
    TENANT_ID  INTEGER                NOT NULL,
    APP_ID     INTEGER                NOT NULL,
    TYPE       VARCHAR(255)           NOT NULL,
    CONTENT    BLOB                            DEFAULT NULL,
    IS_ENABLED CHAR(1)                NOT NULL DEFAULT '0',
    PRIMARY KEY (ID)
  )
    ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS SP_TEMPLATE (
    ID          INTEGER AUTO_INCREMENT NOT NULL,
    TENANT_ID   INTEGER                NOT NULL,
    NAME        VARCHAR(255)           NOT NULL,
    DESCRIPTION VARCHAR(1023),
    CONTENT     BLOB DEFAULT NULL,
    PRIMARY KEY (ID),
    CONSTRAINT SP_TEMPLATE_CONSTRAINT UNIQUE (TENANT_ID, NAME)
  )
    ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS IDN_AUTH_WAIT_STATUS (
    ID            INTEGER AUTO_INCREMENT NOT NULL,
    TENANT_ID     INTEGER                NOT NULL,
    LONG_WAIT_KEY VARCHAR(255)           NOT NULL,
    WAIT_STATUS   CHAR(1)                NOT NULL DEFAULT '1',
    TIME_CREATED  TIMESTAMP              NOT NULL DEFAULT CURRENT_TIMESTAMP,
    EXPIRE_TIME   TIMESTAMP              NOT NULL DEFAULT CURRENT_TIMESTAMP,
    PRIMARY KEY (ID),
    CONSTRAINT IDN_AUTH_WAIT_STATUS_KEY UNIQUE (LONG_WAIT_KEY)
  )
    ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS IDP (
    ID                         INTEGER               AUTO_INCREMENT,
    TENANT_ID                  INTEGER,
    NAME                       VARCHAR(254) NOT NULL,
    IS_ENABLED                 CHAR(1)      NOT NULL DEFAULT '1',
    IS_PRIMARY                 CHAR(1)      NOT NULL DEFAULT '0',
    HOME_REALM_ID              VARCHAR(254),
    IMAGE                      MEDIUMBLOB,
    CERTIFICATE                BLOB,
    ALIAS                      VARCHAR(254),
    INBOUND_PROV_ENABLED       CHAR(1)      NOT NULL DEFAULT '0',
    INBOUND_PROV_USER_STORE_ID VARCHAR(254),
    USER_CLAIM_URI             VARCHAR(254),
    ROLE_CLAIM_URI             VARCHAR(254),
    DESCRIPTION                VARCHAR(1024),
    DEFAULT_AUTHENTICATOR_NAME VARCHAR(254),
    DEFAULT_PRO_CONNECTOR_NAME VARCHAR(254),
    PROVISIONING_ROLE          VARCHAR(128),
    IS_FEDERATION_HUB          CHAR(1)      NOT NULL DEFAULT '0',
    IS_LOCAL_CLAIM_DIALECT     CHAR(1)      NOT NULL DEFAULT '0',
    DISPLAY_NAME               VARCHAR(255),
    IMAGE_URL                  VARCHAR(1024),
    UUID                       CHAR(36) NOT NULL,
    PRIMARY KEY (ID),
    UNIQUE (TENANT_ID, NAME),
    UNIQUE (UUID)
  )
    ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS IDP_ROLE (
    ID        INTEGER AUTO_INCREMENT,
    IDP_ID    INTEGER,
    TENANT_ID INTEGER,
    ROLE      VARCHAR(254),
    PRIMARY KEY (ID),
    UNIQUE (IDP_ID, ROLE),
    FOREIGN KEY (IDP_ID) REFERENCES IDP (ID)
      ON DELETE CASCADE
  )
    ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS IDP_ROLE_MAPPING (
    ID            INTEGER AUTO_INCREMENT,
    IDP_ROLE_ID   INTEGER,
    TENANT_ID     INTEGER,
    USER_STORE_ID VARCHAR(253),
    LOCAL_ROLE    VARCHAR(253),
    PRIMARY KEY (ID),
    UNIQUE (IDP_ROLE_ID, TENANT_ID, USER_STORE_ID, LOCAL_ROLE),
    FOREIGN KEY (IDP_ROLE_ID) REFERENCES IDP_ROLE (ID)
      ON DELETE CASCADE
  )
    ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS IDP_CLAIM (
    ID        INTEGER AUTO_INCREMENT,
    IDP_ID    INTEGER,
    TENANT_ID INTEGER,
    CLAIM     VARCHAR(254),
    PRIMARY KEY (ID),
    UNIQUE (IDP_ID, CLAIM),
    FOREIGN KEY (IDP_ID) REFERENCES IDP (ID)
      ON DELETE CASCADE
  )
    ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS IDP_CLAIM_MAPPING (
    ID            INTEGER      AUTO_INCREMENT,
    IDP_CLAIM_ID  INTEGER,
    TENANT_ID     INTEGER,
    LOCAL_CLAIM   VARCHAR(253),
    DEFAULT_VALUE VARCHAR(255),
    IS_REQUESTED  VARCHAR(128) DEFAULT '0',
    PRIMARY KEY (ID),
    UNIQUE (IDP_CLAIM_ID, TENANT_ID, LOCAL_CLAIM),
    FOREIGN KEY (IDP_CLAIM_ID) REFERENCES IDP_CLAIM (ID)
      ON DELETE CASCADE
  )
    ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS IDP_AUTHENTICATOR (
    ID           INTEGER AUTO_INCREMENT,
    TENANT_ID    INTEGER,
    IDP_ID       INTEGER,
    NAME         VARCHAR(255) NOT NULL,
    IS_ENABLED   CHAR(1) DEFAULT '1',
    DISPLAY_NAME VARCHAR(255),
    PRIMARY KEY (ID),
    UNIQUE (TENANT_ID, IDP_ID, NAME),
    FOREIGN KEY (IDP_ID) REFERENCES IDP (ID)
      ON DELETE CASCADE
  )
    ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS IDP_METADATA (
    ID           INTEGER AUTO_INCREMENT,
    IDP_ID       INTEGER,
    NAME         VARCHAR(255) NOT NULL,
    VALUE        VARCHAR(255) NOT NULL,
    DISPLAY_NAME VARCHAR(255),
    TENANT_ID    INTEGER DEFAULT -1,
    PRIMARY KEY (ID),
    CONSTRAINT IDP_METADATA_CONSTRAINT UNIQUE (IDP_ID, NAME),
    FOREIGN KEY (IDP_ID) REFERENCES IDP (ID)
      ON DELETE CASCADE
  )
    ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS IDP_AUTHENTICATOR_PROPERTY (
    ID               INTEGER AUTO_INCREMENT,
    TENANT_ID        INTEGER,
    AUTHENTICATOR_ID INTEGER,
    PROPERTY_KEY     VARCHAR(255) NOT NULL,
    PROPERTY_VALUE   VARCHAR(2047),
    IS_SECRET        CHAR(1) DEFAULT '0',
    PRIMARY KEY (ID),
    UNIQUE (TENANT_ID, AUTHENTICATOR_ID, PROPERTY_KEY),
    FOREIGN KEY (AUTHENTICATOR_ID) REFERENCES IDP_AUTHENTICATOR (ID)
      ON DELETE CASCADE
  )
    ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS IDP_PROVISIONING_CONFIG (
    ID                          INTEGER AUTO_INCREMENT,
    TENANT_ID                   INTEGER,
    IDP_ID                      INTEGER,
    PROVISIONING_CONNECTOR_TYPE VARCHAR(255) NOT NULL,
    IS_ENABLED                  CHAR(1) DEFAULT '0',
    IS_BLOCKING                 CHAR(1) DEFAULT '0',
    IS_RULES_ENABLED            CHAR(1) DEFAULT '0',
    PRIMARY KEY (ID),
    UNIQUE (TENANT_ID, IDP_ID, PROVISIONING_CONNECTOR_TYPE),
    FOREIGN KEY (IDP_ID) REFERENCES IDP (ID)
      ON DELETE CASCADE
  )
    ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS IDP_PROV_CONFIG_PROPERTY (
    ID                     INTEGER AUTO_INCREMENT,
    TENANT_ID              INTEGER,
    PROVISIONING_CONFIG_ID INTEGER,
    PROPERTY_KEY           VARCHAR(255) NOT NULL,
    PROPERTY_VALUE         VARCHAR(2048),
    PROPERTY_BLOB_VALUE    BLOB,
    PROPERTY_TYPE          CHAR(32)     NOT NULL,
    IS_SECRET              CHAR(1) DEFAULT '0',
    PRIMARY KEY (ID),
    UNIQUE (TENANT_ID, PROVISIONING_CONFIG_ID, PROPERTY_KEY),
    FOREIGN KEY (PROVISIONING_CONFIG_ID) REFERENCES IDP_PROVISIONING_CONFIG (ID)
  )
    ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS IDP_PROVISIONING_ENTITY (
    ID                     INTEGER AUTO_INCREMENT,
    PROVISIONING_CONFIG_ID INTEGER,
    ENTITY_TYPE            VARCHAR(255) NOT NULL,
    ENTITY_LOCAL_USERSTORE VARCHAR(255) NOT NULL,
    ENTITY_NAME            VARCHAR(255) NOT NULL,
    ENTITY_VALUE           VARCHAR(255),
    TENANT_ID              INTEGER,
    ENTITY_LOCAL_ID        VARCHAR(255),
    PRIMARY KEY (ID),
    UNIQUE (ENTITY_TYPE, TENANT_ID, ENTITY_LOCAL_USERSTORE, ENTITY_NAME, PROVISIONING_CONFIG_ID),
    UNIQUE (PROVISIONING_CONFIG_ID, ENTITY_TYPE, ENTITY_VALUE),
    FOREIGN KEY (PROVISIONING_CONFIG_ID) REFERENCES IDP_PROVISIONING_CONFIG (ID)
      ON DELETE CASCADE
  )
    ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS IDP_LOCAL_CLAIM (
    ID            INTEGER      AUTO_INCREMENT,
    TENANT_ID     INTEGER,
    IDP_ID        INTEGER,
    CLAIM_URI     VARCHAR(255) NOT NULL,
    DEFAULT_VALUE VARCHAR(255),
    IS_REQUESTED  VARCHAR(128) DEFAULT '0',
    PRIMARY KEY (ID),
    UNIQUE (TENANT_ID, IDP_ID, CLAIM_URI),
    FOREIGN KEY (IDP_ID) REFERENCES IDP (ID)
      ON DELETE CASCADE
  )
    ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS IDN_ASSOCIATED_ID (
    ID          INTEGER AUTO_INCREMENT,
    IDP_USER_ID VARCHAR(255) NOT NULL,
    TENANT_ID   INTEGER DEFAULT -1234,
    IDP_ID      INTEGER      NOT NULL,
    DOMAIN_NAME VARCHAR(255) NOT NULL,
    USER_NAME   VARCHAR(255) NOT NULL,
    ASSOCIATION_ID CHAR(36) NOT NULL,
    PRIMARY KEY (ID),
    UNIQUE (IDP_USER_ID, TENANT_ID, IDP_ID),
    FOREIGN KEY (IDP_ID) REFERENCES IDP (ID)
      ON DELETE CASCADE
  )
    ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS IDN_USER_ACCOUNT_ASSOCIATION (
    ASSOCIATION_KEY VARCHAR(255) NOT NULL,
    TENANT_ID       INTEGER,
    DOMAIN_NAME     VARCHAR(255) NOT NULL,
    USER_NAME       VARCHAR(255) NOT NULL,
    PRIMARY KEY (TENANT_ID, DOMAIN_NAME, USER_NAME)
  )
    ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS FIDO_DEVICE_STORE (
    TENANT_ID       INTEGER,
    DOMAIN_NAME     VARCHAR(255)  NOT NULL,
    USER_NAME       VARCHAR(45)   NOT NULL,
    TIME_REGISTERED TIMESTAMP,
    KEY_HANDLE      VARCHAR(200)  NOT NULL,
    DEVICE_DATA     VARCHAR(2048) NOT NULL,
    PRIMARY KEY (TENANT_ID, DOMAIN_NAME, USER_NAME, KEY_HANDLE)
  )
    ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS FIDO2_DEVICE_STORE (
    TENANT_ID INTEGER,
    DOMAIN_NAME VARCHAR(255) NOT NULL,
    USER_NAME VARCHAR(45) NOT NULL,
    TIME_REGISTERED TIMESTAMP,
    USER_HANDLE VARCHAR(64) NOT NULL,
    CREDENTIAL_ID VARCHAR(200) NOT NULL,
    PUBLIC_KEY_COSE VARCHAR(1024) NOT NULL,
    SIGNATURE_COUNT BIGINT,
    USER_IDENTITY VARCHAR(512) NOT NULL,
    DISPLAY_NAME VARCHAR(255),
    IS_USERNAMELESS_SUPPORTED CHAR(1) DEFAULT '0',
    PRIMARY KEY (CREDENTIAL_ID, USER_HANDLE)
  )
    ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS WF_REQUEST (
    UUID           VARCHAR(45),
    CREATED_BY     VARCHAR(255),
    TENANT_ID      INTEGER   DEFAULT -1,
    OPERATION_TYPE VARCHAR(50),
    CREATED_AT     TIMESTAMP,
    UPDATED_AT     TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    STATUS         VARCHAR(30),
    REQUEST        BLOB,
    PRIMARY KEY (UUID)
  )
    ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS WF_BPS_PROFILE (
    PROFILE_NAME      VARCHAR(45),
    HOST_URL_MANAGER  VARCHAR(255),
    HOST_URL_WORKER   VARCHAR(255),
    USERNAME          VARCHAR(100),
    PASSWORD          VARCHAR(1023),
    CALLBACK_HOST     VARCHAR(45),
    CALLBACK_USERNAME VARCHAR(100),
    CALLBACK_PASSWORD VARCHAR(255),
    TENANT_ID         INTEGER DEFAULT -1,
    PRIMARY KEY (PROFILE_NAME, TENANT_ID)
  )
    ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS WF_WORKFLOW (
    ID          VARCHAR(45),
    WF_NAME     VARCHAR(45),
    DESCRIPTION VARCHAR(255),
    TEMPLATE_ID VARCHAR(45),
    IMPL_ID     VARCHAR(45),
    TENANT_ID   INTEGER DEFAULT -1,
    PRIMARY KEY (ID)
  )
    ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS WF_WORKFLOW_ASSOCIATION (
    ID              INTEGER NOT NULL AUTO_INCREMENT,
    ASSOC_NAME      VARCHAR(45),
    EVENT_ID        VARCHAR(45),
    ASSOC_CONDITION VARCHAR(2000),
    WORKFLOW_ID     VARCHAR(45),
    IS_ENABLED      CHAR(1)          DEFAULT '1',
    TENANT_ID       INTEGER          DEFAULT -1,
    PRIMARY KEY (ID),
    FOREIGN KEY (WORKFLOW_ID) REFERENCES WF_WORKFLOW (ID)
      ON DELETE CASCADE
  )
    ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS WF_WORKFLOW_CONFIG_PARAM (
    WORKFLOW_ID  VARCHAR(45),
    PARAM_NAME   VARCHAR(45),
    PARAM_VALUE  VARCHAR(1000),
    PARAM_QNAME  VARCHAR(45),
    PARAM_HOLDER VARCHAR(45),
    TENANT_ID    INTEGER DEFAULT -1,
    PRIMARY KEY (WORKFLOW_ID, PARAM_NAME, PARAM_QNAME, PARAM_HOLDER),
    FOREIGN KEY (WORKFLOW_ID) REFERENCES WF_WORKFLOW (ID)
      ON DELETE CASCADE
  )
    ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS WF_REQUEST_ENTITY_RELATIONSHIP (
    REQUEST_ID  VARCHAR(45),
    ENTITY_NAME VARCHAR(255),
    ENTITY_TYPE VARCHAR(50),
    TENANT_ID   INTEGER DEFAULT -1,
    PRIMARY KEY (REQUEST_ID, ENTITY_NAME, ENTITY_TYPE, TENANT_ID),
    FOREIGN KEY (REQUEST_ID) REFERENCES WF_REQUEST (UUID)
      ON DELETE CASCADE
  )
    ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS WF_WORKFLOW_REQUEST_RELATION (
    RELATIONSHIP_ID VARCHAR(45),
    WORKFLOW_ID     VARCHAR(45),
    REQUEST_ID      VARCHAR(45),
    UPDATED_AT      TIMESTAMP,
    STATUS          VARCHAR(30),
    TENANT_ID       INTEGER DEFAULT -1,
    PRIMARY KEY (RELATIONSHIP_ID),
    FOREIGN KEY (WORKFLOW_ID) REFERENCES WF_WORKFLOW (ID)
      ON DELETE CASCADE,
    FOREIGN KEY (REQUEST_ID) REFERENCES WF_REQUEST (UUID)
      ON DELETE CASCADE
  )
    ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS IDN_RECOVERY_DATA (
    USER_NAME      VARCHAR(255) NOT NULL,
    USER_DOMAIN    VARCHAR(127) NOT NULL,
    TENANT_ID      INTEGER               DEFAULT -1,
    CODE           VARCHAR(255) NOT NULL,
    SCENARIO       VARCHAR(255) NOT NULL,
    STEP           VARCHAR(127) NOT NULL,
    TIME_CREATED   TIMESTAMP    NOT NULL DEFAULT CURRENT_TIMESTAMP,
    REMAINING_SETS VARCHAR(2500)         DEFAULT NULL,
    PRIMARY KEY (USER_NAME, USER_DOMAIN, TENANT_ID, SCENARIO, STEP),
    UNIQUE (CODE)
  )
    ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS IDN_PASSWORD_HISTORY_DATA (
    ID           INTEGER      NOT NULL AUTO_INCREMENT,
    USER_NAME    VARCHAR(255) NOT NULL,
    USER_DOMAIN  VARCHAR(127) NOT NULL,
    TENANT_ID    INTEGER               DEFAULT -1,
    SALT_VALUE   VARCHAR(255),
    HASH         VARCHAR(255) NOT NULL,
    TIME_CREATED TIMESTAMP    NOT NULL DEFAULT CURRENT_TIMESTAMP,
    PRIMARY KEY (ID),
    UNIQUE (USER_NAME, USER_DOMAIN, TENANT_ID, SALT_VALUE, HASH)
  )
    ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS IDN_CLAIM_DIALECT (
    ID          INTEGER      NOT NULL AUTO_INCREMENT,
    DIALECT_URI VARCHAR(255) NOT NULL,
    TENANT_ID   INTEGER      NOT NULL,
    PRIMARY KEY (ID),
    CONSTRAINT DIALECT_URI_CONSTRAINT UNIQUE (DIALECT_URI, TENANT_ID)
  )
    ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS IDN_CLAIM (
    ID         INTEGER      NOT NULL AUTO_INCREMENT,
    DIALECT_ID INTEGER      NOT NULL,
    CLAIM_URI  VARCHAR(255) NOT NULL,
    TENANT_ID  INTEGER      NOT NULL,
    PRIMARY KEY (ID),
    FOREIGN KEY (DIALECT_ID) REFERENCES IDN_CLAIM_DIALECT (ID)
      ON DELETE CASCADE,
    CONSTRAINT CLAIM_URI_CONSTRAINT UNIQUE (DIALECT_ID, CLAIM_URI, TENANT_ID)
  )
    ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS IDN_CLAIM_MAPPED_ATTRIBUTE (
    ID                     INTEGER      NOT NULL AUTO_INCREMENT,
    LOCAL_CLAIM_ID         INTEGER,
    USER_STORE_DOMAIN_NAME VARCHAR(255) NOT NULL,
    ATTRIBUTE_NAME         VARCHAR(255) NOT NULL,
    TENANT_ID              INTEGER      NOT NULL,
    PRIMARY KEY (ID),
    FOREIGN KEY (LOCAL_CLAIM_ID) REFERENCES IDN_CLAIM (ID)
      ON DELETE CASCADE,
    CONSTRAINT USER_STORE_DOMAIN_CONSTRAINT UNIQUE (LOCAL_CLAIM_ID, USER_STORE_DOMAIN_NAME, TENANT_ID)
  )
    ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS IDN_CLAIM_PROPERTY (
    ID             INTEGER      NOT NULL AUTO_INCREMENT,
    LOCAL_CLAIM_ID INTEGER,
    PROPERTY_NAME  VARCHAR(255) NOT NULL,
    PROPERTY_VALUE VARCHAR(255) NOT NULL,
    TENANT_ID      INTEGER      NOT NULL,
    PRIMARY KEY (ID),
    FOREIGN KEY (LOCAL_CLAIM_ID) REFERENCES IDN_CLAIM (ID)
      ON DELETE CASCADE,
    CONSTRAINT PROPERTY_NAME_CONSTRAINT UNIQUE (LOCAL_CLAIM_ID, PROPERTY_NAME, TENANT_ID)
  )
    ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS IDN_CLAIM_MAPPING (
    ID                    INTEGER NOT NULL AUTO_INCREMENT,
    EXT_CLAIM_ID          INTEGER NOT NULL,
    MAPPED_LOCAL_CLAIM_ID INTEGER NOT NULL,
    TENANT_ID             INTEGER NOT NULL,
    PRIMARY KEY (ID),
    FOREIGN KEY (EXT_CLAIM_ID) REFERENCES IDN_CLAIM (ID)
      ON DELETE CASCADE,
    FOREIGN KEY (MAPPED_LOCAL_CLAIM_ID) REFERENCES IDN_CLAIM (ID)
      ON DELETE CASCADE,
    CONSTRAINT EXT_TO_LOC_MAPPING_CONSTRN UNIQUE (EXT_CLAIM_ID, TENANT_ID)
  )
    ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS IDN_SAML2_ASSERTION_STORE (
    ID                            INTEGER NOT NULL AUTO_INCREMENT,
    SAML2_ID                      VARCHAR(255),
    SAML2_ISSUER                  VARCHAR(255),
    SAML2_SUBJECT                 VARCHAR(255),
    SAML2_SESSION_INDEX           VARCHAR(255),
    SAML2_AUTHN_CONTEXT_CLASS_REF VARCHAR(255),
    SAML2_ASSERTION               VARCHAR(4096),
    PRIMARY KEY (ID)
  )
    ENGINE NDB;
  
  CREATE TABLE IDN_SAML2_ARTIFACT_STORE (
    ID              INT(11)      NOT NULL AUTO_INCREMENT,
    SOURCE_ID       VARCHAR(255) NOT NULL,
    MESSAGE_HANDLER VARCHAR(255) NOT NULL,
    AUTHN_REQ_DTO   BLOB         NOT NULL,
    SESSION_ID      VARCHAR(255) NOT NULL,
    EXP_TIMESTAMP   TIMESTAMP    NOT NULL,
    INIT_TIMESTAMP  TIMESTAMP    NOT NULL DEFAULT CURRENT_TIMESTAMP,
    ASSERTION_ID    VARCHAR(255),
    PRIMARY KEY (`ID`)
  )
    ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS IDN_OIDC_JTI (
    JWT_ID       VARCHAR(255) NOT NULL,
    EXP_TIME     TIMESTAMP    NOT NULL,
    TIME_CREATED TIMESTAMP    NOT NULL DEFAULT CURRENT_TIMESTAMP,
    PRIMARY KEY (JWT_ID)
  )
    ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS IDN_OIDC_PROPERTY (
    ID             INTEGER      NOT NULL AUTO_INCREMENT,
    TENANT_ID      INTEGER,
    CONSUMER_KEY   VARCHAR(255),
    PROPERTY_KEY   VARCHAR(255) NOT NULL,
    PROPERTY_VALUE VARCHAR(2047),
    PRIMARY KEY (ID),
    FOREIGN KEY (CONSUMER_KEY) REFERENCES IDN_OAUTH_CONSUMER_APPS (CONSUMER_KEY)
      ON DELETE CASCADE
  )
    ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS IDN_OIDC_REQ_OBJECT_REFERENCE (
    ID               INTEGER NOT NULL AUTO_INCREMENT,
    CONSUMER_KEY_ID  INTEGER,
    CODE_ID          VARCHAR(255),
    TOKEN_ID         VARCHAR(255),
    SESSION_DATA_KEY VARCHAR(255),
    PRIMARY KEY (ID),
    FOREIGN KEY (CONSUMER_KEY_ID) REFERENCES IDN_OAUTH_CONSUMER_APPS (ID)
      ON DELETE CASCADE,
    FOREIGN KEY (TOKEN_ID) REFERENCES IDN_OAUTH2_ACCESS_TOKEN (TOKEN_ID)
      ON DELETE CASCADE,
    FOREIGN KEY (CODE_ID) REFERENCES IDN_OAUTH2_AUTHORIZATION_CODE (CODE_ID)
      ON DELETE CASCADE
  )
    ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS IDN_OIDC_REQ_OBJECT_CLAIMS (
    ID              INTEGER NOT NULL AUTO_INCREMENT,
    REQ_OBJECT_ID   INTEGER,
    CLAIM_ATTRIBUTE VARCHAR(255),
    ESSENTIAL       CHAR(1) NOT NULL DEFAULT '0',
    VALUE           VARCHAR(255),
    IS_USERINFO     CHAR(1) NOT NULL DEFAULT '0',
    PRIMARY KEY (ID),
    FOREIGN KEY (REQ_OBJECT_ID) REFERENCES IDN_OIDC_REQ_OBJECT_REFERENCE (ID)
      ON DELETE CASCADE
  )
    ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS IDN_OIDC_REQ_OBJ_CLAIM_VALUES (
    ID                   INTEGER NOT NULL AUTO_INCREMENT,
    REQ_OBJECT_CLAIMS_ID INTEGER,
    CLAIM_VALUES         VARCHAR(255),
    PRIMARY KEY (ID),
    FOREIGN KEY (REQ_OBJECT_CLAIMS_ID) REFERENCES IDN_OIDC_REQ_OBJECT_CLAIMS (ID)
      ON DELETE CASCADE
  )
    ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS IDN_CERTIFICATE (
    ID                 INTEGER NOT NULL AUTO_INCREMENT,
    NAME               VARCHAR(100),
    CERTIFICATE_IN_PEM BLOB,
    TENANT_ID          INTEGER          DEFAULT 0,
    PRIMARY KEY (ID),
    CONSTRAINT CERTIFICATE_UNIQUE_KEY UNIQUE (NAME, TENANT_ID)
  )
    ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS IDN_OIDC_SCOPE_CLAIM_MAPPING (
    ID                INTEGER NOT NULL AUTO_INCREMENT,
    SCOPE_ID          INTEGER NOT NULL,
    EXTERNAL_CLAIM_ID INTEGER NOT NULL,
    PRIMARY KEY (ID),
    FOREIGN KEY (SCOPE_ID) REFERENCES IDN_OAUTH2_SCOPE (SCOPE_ID)
      ON DELETE CASCADE,
    FOREIGN KEY (EXTERNAL_CLAIM_ID) REFERENCES IDN_CLAIM (ID)
      ON DELETE CASCADE,
    UNIQUE (SCOPE_ID, EXTERNAL_CLAIM_ID)
  )
    ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS IDN_FUNCTION_LIBRARY (
  	NAME VARCHAR(255) NOT NULL,
  	DESCRIPTION VARCHAR(1023),
  	TYPE VARCHAR(255) NOT NULL,
  	TENANT_ID INTEGER NOT NULL,
  	DATA BLOB NOT NULL,
  	PRIMARY KEY (TENANT_ID,NAME)
  )ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS IDN_OAUTH2_CIBA_AUTH_CODE (
      AUTH_CODE_KEY CHAR (36),
      AUTH_REQ_ID CHAR (36),
      ISSUED_TIME TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
      CONSUMER_KEY VARCHAR(255),
      LAST_POLLED_TIME TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
      POLLING_INTERVAL INTEGER,
      EXPIRES_IN  INTEGER,
      AUTHENTICATED_USER_NAME VARCHAR(255),
      USER_STORE_DOMAIN VARCHAR(100),
      TENANT_ID INTEGER,
      AUTH_REQ_STATUS VARCHAR (100) DEFAULT 'REQUESTED',
      IDP_ID INTEGER,
      UNIQUE(AUTH_REQ_ID),
      PRIMARY KEY (AUTH_CODE_KEY),
      FOREIGN KEY (CONSUMER_KEY) REFERENCES IDN_OAUTH_CONSUMER_APPS(CONSUMER_KEY) ON DELETE CASCADE
  )ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS IDN_OAUTH2_CIBA_REQUEST_SCOPES (
      ID            INTEGER NOT NULL AUTO_INCREMENT,
      AUTH_CODE_KEY CHAR (36),
      SCOPE VARCHAR (255),
      FOREIGN KEY (AUTH_CODE_KEY) REFERENCES IDN_OAUTH2_CIBA_AUTH_CODE(AUTH_CODE_KEY) ON DELETE CASCADE,
      PRIMARY KEY (ID)
  )ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS IDN_FED_AUTH_SESSION_MAPPING (
  	IDP_SESSION_ID   VARCHAR(255) NOT NULL,
  	SESSION_ID       VARCHAR(255) NOT NULL,
  	IDP_NAME         VARCHAR(255) NOT NULL,
  	AUTHENTICATOR_ID VARCHAR(255),
  	PROTOCOL_TYPE    VARCHAR(255),
  	TIME_CREATED     TIMESTAMP    NOT NULL DEFAULT CURRENT_TIMESTAMP,
  	PRIMARY KEY (IDP_SESSION_ID)
  )ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS IDN_CONFIG_TYPE (
      ID VARCHAR(255) NOT NULL,
      NAME VARCHAR(255) NOT NULL,
      DESCRIPTION VARCHAR(1023) NULL,
      PRIMARY KEY (ID),
      CONSTRAINT TYPE_NAME_CONSTRAINT UNIQUE (NAME)
  )ENGINE NDB;
  
  INSERT INTO IDN_CONFIG_TYPE (ID, NAME, DESCRIPTION) VALUES
  ('9ab0ef95-13e9-4ed5-afaf-d29bed62f7bd', 'IDP_TEMPLATE', 'Template type to uniquely identify IDP templates'),
  ('3c4ac3d0-5903-4e3d-aaca-38df65b33bfd', 'APPLICATION_TEMPLATE', 'Template type to uniquely identify Application templates'),
  ('8ec6dbf1-218a-49bf-bc34-0d2db52d151c', 'CORS_CONFIGURATION', 'A resource type to keep the tenant CORS configurations'),
  ('669b99ca-cdb0-44a6-8cae-babed3b585df', 'Publisher', 'A resource type to keep the event publisher configurations'),
  ('73f6d9ca-62f4-4566-bab9-2a930ae51ba8', 'BRANDING_PREFERENCES', 'A resource type to keep the tenant branding preferences');
  
  CREATE TABLE IF NOT EXISTS IDN_CONFIG_RESOURCE (
      ID VARCHAR(255) NOT NULL,
      TENANT_ID INT NOT NULL,
      NAME VARCHAR(255) NOT NULL,
      CREATED_TIME TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
      LAST_MODIFIED TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
      HAS_FILE tinyint(1) NOT NULL,
      HAS_ATTRIBUTE tinyint(1) NOT NULL,
      TYPE_ID VARCHAR(255) NOT NULL,
      PRIMARY KEY (ID),
      CONSTRAINT NAME_TENANT_TYPE_CONSTRAINT UNIQUE (NAME, TENANT_ID, TYPE_ID)
  )ENGINE NDB;
  ALTER TABLE IDN_CONFIG_RESOURCE ADD CONSTRAINT TYPE_ID_FOREIGN_CONSTRAINT FOREIGN KEY (TYPE_ID) REFERENCES
  IDN_CONFIG_TYPE (ID) ON DELETE CASCADE;
  
  CREATE TABLE IF NOT EXISTS IDN_CONFIG_ATTRIBUTE (
      ID VARCHAR(255) NOT NULL,
      RESOURCE_ID VARCHAR(255) NOT NULL,
      ATTR_KEY VARCHAR(255) NOT NULL,
      ATTR_VALUE VARCHAR(1023) NULL,
      PRIMARY KEY (ID),
      CONSTRAINT RESOURCE_KEY_VAL_CONSTRAINT UNIQUE (RESOURCE_ID(255), ATTR_KEY(255))
  )ENGINE NDB;
  ALTER TABLE IDN_CONFIG_ATTRIBUTE ADD CONSTRAINT RESOURCE_ID_ATTRIBUTE_FOREIGN_CONSTRAINT FOREIGN KEY (RESOURCE_ID)
  REFERENCES IDN_CONFIG_RESOURCE (ID) ON DELETE CASCADE;
  
  CREATE TABLE IF NOT EXISTS IDN_CONFIG_FILE (
      ID VARCHAR(255) NOT NULL,
      VALUE BLOB NULL,
      RESOURCE_ID VARCHAR(255) NOT NULL,
      NAME VARCHAR(255) NULL,
      PRIMARY KEY (ID)
  )ENGINE NDB;
  ALTER TABLE IDN_CONFIG_FILE ADD CONSTRAINT RESOURCE_ID_FILE_FOREIGN_CONSTRAINT FOREIGN KEY (RESOURCE_ID) REFERENCES
  IDN_CONFIG_RESOURCE (ID);
  
  
  CREATE TABLE IDN_REMOTE_FETCH_CONFIG (
  	ID VARCHAR(255) NOT NULL,
  	TENANT_ID INT NOT NULL,
  	IS_ENABLED CHAR(1) NOT NULL,
  	REPO_MANAGER_TYPE VARCHAR(255) NOT NULL,
  	ACTION_LISTENER_TYPE VARCHAR(255) NOT NULL,
  	CONFIG_DEPLOYER_TYPE VARCHAR(255) NOT NULL,
  	REMOTE_FETCH_NAME VARCHAR(255),
  	REMOTE_RESOURCE_URI VARCHAR(255) NOT NULL,
  	ATTRIBUTES_JSON MEDIUMTEXT NOT NULL,
  	PRIMARY KEY (ID),
  	CONSTRAINT UC_REMOTE_RESOURCE_TYPE UNIQUE (TENANT_ID, CONFIG_DEPLOYER_TYPE)
  )ENGINE NDB;
  
  CREATE TABLE IDN_REMOTE_FETCH_REVISIONS (
  	ID VARCHAR(255) NOT NULL,
  	CONFIG_ID VARCHAR(255) NOT NULL,
  	FILE_PATH VARCHAR(255) NOT NULL,
  	FILE_HASH VARCHAR(255),
  	DEPLOYED_DATE TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  	LAST_SYNC_TIME TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  	DEPLOYMENT_STATUS VARCHAR(255),
  	ITEM_NAME VARCHAR(255),
  	DEPLOY_ERR_LOG MEDIUMTEXT,
  	PRIMARY KEY (ID),
  	FOREIGN KEY (CONFIG_ID) REFERENCES IDN_REMOTE_FETCH_CONFIG(ID),
  	CONSTRAINT UC_REVISIONS UNIQUE (CONFIG_ID, ITEM_NAME)
  )ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS IDN_USER_FUNCTIONALITY_MAPPING (
  	ID VARCHAR(255) NOT NULL,
  	USER_ID VARCHAR(255) NOT NULL,
  	TENANT_ID INTEGER NOT NULL,
  	FUNCTIONALITY_ID VARCHAR(255) NOT NULL,
  	IS_FUNCTIONALITY_LOCKED BOOLEAN NOT NULL,
  	FUNCTIONALITY_UNLOCK_TIME BIGINT NOT NULL,
  	FUNCTIONALITY_LOCK_REASON VARCHAR(1023),
  	FUNCTIONALITY_LOCK_REASON_CODE VARCHAR(255),
  	PRIMARY KEY (ID),
  	CONSTRAINT IDN_USER_FUNCTIONALITY_MAPPING_CONSTRAINT UNIQUE (USER_ID, TENANT_ID, FUNCTIONALITY_ID)
  )ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS IDN_USER_FUNCTIONALITY_PROPERTY (
  	ID VARCHAR(255) NOT NULL,
  	USER_ID VARCHAR(255) NOT NULL,
  	TENANT_ID INTEGER NOT NULL,
  	FUNCTIONALITY_ID VARCHAR(255) NOT NULL,
  	PROPERTY_NAME VARCHAR(255),
  	PROPERTY_VALUE VARCHAR(255),
  	PRIMARY KEY (ID),
  	CONSTRAINT IDN_USER_FUNCTIONALITY_PROPERTY_CONSTRAINT UNIQUE (USER_ID, TENANT_ID, FUNCTIONALITY_ID, PROPERTY_NAME)
  )ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS IDN_CORS_ORIGIN (
      ID                INT           NOT NULL AUTO_INCREMENT,
      TENANT_ID         INT           NOT NULL,
      ORIGIN            VARCHAR(2048) NOT NULL,
      UUID              CHAR(36)      NOT NULL,
  
      PRIMARY KEY (ID),
      UNIQUE (TENANT_ID, ORIGIN),
      UNIQUE (UUID)
  ) ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS IDN_CORS_ASSOCIATION (
      IDN_CORS_ORIGIN_ID  INT NOT NULL,
      SP_APP_ID           INT NOT NULL,
  
      PRIMARY KEY (IDN_CORS_ORIGIN_ID, SP_APP_ID),
      FOREIGN KEY (IDN_CORS_ORIGIN_ID) REFERENCES IDN_CORS_ORIGIN (ID) ON DELETE CASCADE,
      FOREIGN KEY (SP_APP_ID) REFERENCES SP_APP (ID) ON DELETE CASCADE
  ) ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS IDN_OAUTH2_USER_CONSENT (
      ID INTEGER NOT NULL AUTO_INCREMENT,
      USER_ID VARCHAR(255) NOT NULL,
      APP_ID CHAR(36) NOT NULL,
      TENANT_ID INTEGER NOT NULL DEFAULT -1,
      CONSENT_ID VARCHAR(255) NOT NULL,
  
      PRIMARY KEY (ID),
      FOREIGN KEY (APP_ID) REFERENCES SP_APP(UUID) ON DELETE CASCADE,
      UNIQUE (USER_ID, APP_ID, TENANT_ID),
      UNIQUE (CONSENT_ID)
  ) ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS IDN_OAUTH2_USER_CONSENTED_SCOPES (
      ID INTEGER NOT NULL AUTO_INCREMENT,
      CONSENT_ID VARCHAR(255) NOT NULL,
      TENANT_ID INTEGER NOT NULL DEFAULT -1,
      SCOPE VARCHAR(255) NOT NULL,
      CONSENT BOOLEAN NOT NULL DEFAULT 1,
  
      PRIMARY KEY (ID),
      FOREIGN KEY (CONSENT_ID) REFERENCES IDN_OAUTH2_USER_CONSENT(CONSENT_ID) ON DELETE CASCADE,
      UNIQUE (CONSENT_ID, SCOPE)
  ) ENGINE NDB;
  
  CREATE TABLE IF NOT EXISTS IDN_SECRET_TYPE (
      ID VARCHAR(255) NOT NULL,
      NAME VARCHAR(255) NOT NULL,
      DESCRIPTION VARCHAR(1023) NULL,
      PRIMARY KEY (ID),
      CONSTRAINT SECRET_TYPE_NAME_CONSTRAINT UNIQUE (NAME)
  )ENGINE NDB;
  
  INSERT INTO IDN_SECRET_TYPE (ID, NAME, DESCRIPTION) VALUES
  ('1358bdbf-e0cc-4268-a42c-c3e0960e13f0', 'ADAPTIVE_AUTH_CALL_CHOREO', 'Secret type to uniquely identify secrets relevant to callChoreo adaptive auth function');
  
  CREATE TABLE IF NOT EXISTS IDN_SECRET (
      ID VARCHAR(255) NOT NULL,
      TENANT_ID INT NOT NULL,
      SECRET_NAME VARCHAR(255) NOT NULL,
      SECRET_VALUE VARCHAR(8000) NOT NULL,
      CREATED_TIME TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
      LAST_MODIFIED TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
      TYPE_ID       VARCHAR(255) NOT NULL,
      DESCRIPTION VARCHAR(1023) NULL,
      PRIMARY KEY (ID),
      FOREIGN KEY (TYPE_ID) REFERENCES IDN_SECRET_TYPE(ID) ON DELETE CASCADE,
      UNIQUE (SECRET_NAME, TENANT_ID, TYPE_ID)
  )ENGINE NDB;
  
  -- --------------------------- INDEX CREATION -----------------------------
  -- IDN_OAUTH2_ACCESS_TOKEN --
  CREATE INDEX IDX_TC
    ON IDN_OAUTH2_ACCESS_TOKEN (TIME_CREATED);
  CREATE INDEX IDX_ATH
    ON IDN_OAUTH2_ACCESS_TOKEN (ACCESS_TOKEN_HASH);
  CREATE INDEX IDX_AT_TI_UD
    ON IDN_OAUTH2_ACCESS_TOKEN (AUTHZ_USER, TENANT_ID, TOKEN_STATE, USER_DOMAIN);
  CREATE INDEX IDX_AT_AT
    ON IDN_OAUTH2_ACCESS_TOKEN (ACCESS_TOKEN);
  CREATE INDEX IDX_AT_RTH
    ON IDN_OAUTH2_ACCESS_TOKEN (REFRESH_TOKEN_HASH);
  CREATE INDEX IDX_AT_RT
    ON IDN_OAUTH2_ACCESS_TOKEN (REFRESH_TOKEN);
  CREATE INDEX IDX_AT_CKID_AU_TID_UD_TSH_TS
    ON IDN_OAUTH2_ACCESS_TOKEN(CONSUMER_KEY_ID, AUTHZ_USER, TENANT_ID, USER_DOMAIN, TOKEN_SCOPE_HASH, TOKEN_STATE);
  
  -- IDN_OAUTH2_AUTHORIZATION_CODE --
  CREATE INDEX IDX_AUTHORIZATION_CODE_HASH
    ON IDN_OAUTH2_AUTHORIZATION_CODE (AUTHORIZATION_CODE_HASH, CONSUMER_KEY_ID);
  CREATE INDEX IDX_AUTHORIZATION_CODE_AU_TI
    ON IDN_OAUTH2_AUTHORIZATION_CODE (AUTHZ_USER, TENANT_ID, USER_DOMAIN, STATE);
  CREATE INDEX IDX_AC_CKID
    ON IDN_OAUTH2_AUTHORIZATION_CODE (CONSUMER_KEY_ID);
  CREATE INDEX IDX_AC_TID
    ON IDN_OAUTH2_AUTHORIZATION_CODE (TOKEN_ID);
  CREATE INDEX IDX_AC_AC_CKID
    ON IDN_OAUTH2_AUTHORIZATION_CODE (AUTHORIZATION_CODE, CONSUMER_KEY_ID);
  
  -- IDN_SCIM_GROUP --
  CREATE INDEX IDX_IDN_SCIM_GROUP_TI_RN
    ON IDN_SCIM_GROUP (TENANT_ID, ROLE_NAME);
  CREATE INDEX IDX_IDN_SCIM_GROUP_TI_RN_AN
    ON IDN_SCIM_GROUP (TENANT_ID, ROLE_NAME, ATTR_NAME);
  
  -- IDN_AUTH_SESSION_STORE --
  CREATE INDEX IDX_IDN_AUTH_SESSION_TIME
    ON IDN_AUTH_SESSION_STORE (TIME_CREATED);
  
  -- IDN_AUTH_TEMP_SESSION_STORE --
  CREATE INDEX IDX_IDN_AUTH_TMP_SESSION_TIME
    ON IDN_AUTH_TEMP_SESSION_STORE (TIME_CREATED);
  
  -- IDN_OIDC_SCOPE_CLAIM_MAPPING --
  CREATE INDEX IDX_AT_SI_ECI
    ON IDN_OIDC_SCOPE_CLAIM_MAPPING (SCOPE_ID, EXTERNAL_CLAIM_ID);
  
  -- IDN_OAUTH2_SCOPE --
  CREATE INDEX IDX_SC_TID
    ON IDN_OAUTH2_SCOPE (TENANT_ID);
  
  -- IDN_OAUTH2_SCOPE_BINDING --
  CREATE INDEX IDX_SB_SCPID
    ON IDN_OAUTH2_SCOPE_BINDING (SCOPE_ID);
  
  -- IDN_OIDC_REQ_OBJECT_REFERENCE --
  CREATE INDEX IDX_OROR_TID
    ON IDN_OIDC_REQ_OBJECT_REFERENCE (TOKEN_ID);
  
  -- IDN_OAUTH2_ACCESS_TOKEN_SCOPE --
  CREATE INDEX IDX_ATS_TID
    ON IDN_OAUTH2_ACCESS_TOKEN_SCOPE (TOKEN_ID);
  
  -- SP_TEMPLATE --
  CREATE INDEX IDX_SP_TEMPLATE
    ON SP_TEMPLATE (TENANT_ID, NAME);
  
  -- IDN_OAUTH_CONSUMER_APPS --
  CREATE INDEX IDX_OCA_UM_TID_UD_APN
    ON IDN_OAUTH_CONSUMER_APPS(USERNAME,TENANT_ID,USER_DOMAIN, APP_NAME);
  
  -- IDX_SPI_APP --
  CREATE INDEX IDX_SPI_APP
    ON SP_INBOUND_AUTH(APP_ID);
  
  -- IDN_OIDC_PROPERTY --
  CREATE INDEX IDX_IOP_CK
    ON IDN_OIDC_PROPERTY(CONSUMER_KEY);
  
  -- IDN_FIDO2_PROPERTY --
  CREATE INDEX IDX_FIDO2_STR
    ON FIDO2_DEVICE_STORE(USER_NAME, TENANT_ID, DOMAIN_NAME, CREDENTIAL_ID, USER_HANDLE);
  
    -- IDN_AUTH_USER --
  CREATE INDEX IDX_AUTH_USER_UN_TID_DN ON IDN_AUTH_USER (USER_NAME, TENANT_ID, DOMAIN_NAME);
  CREATE INDEX IDX_AUTH_USER_DN_TOD ON IDN_AUTH_USER (DOMAIN_NAME, TENANT_ID);
  
  -- IDN_AUTH_USER_SESSION_MAPPING --
  CREATE INDEX IDX_USER_ID ON IDN_AUTH_USER_SESSION_MAPPING (USER_ID);
  CREATE INDEX IDX_SESSION_ID ON IDN_AUTH_USER_SESSION_MAPPING (SESSION_ID);
  
  -- IDN_ASSOCIATED_ID --
  CREATE INDEX IDX_AI_DN_UN_AI ON IDN_ASSOCIATED_ID(DOMAIN_NAME, USER_NAME, ASSOCIATION_ID);
  
  -- IDN_OAUTH2_TOKEN_BINDING --
  CREATE INDEX IDX_IDN_AUTH_BIND ON IDN_OAUTH2_TOKEN_BINDING (TOKEN_BINDING_REF);
  CREATE INDEX IDX_TK_VALUE_TYPE ON IDN_OAUTH2_TOKEN_BINDING (TOKEN_BINDING_VALUE, TOKEN_BINDING_TYPE);
  
  -- IDN_FED_AUTH_SESSION_MAPPING --
  CREATE INDEX IDX_FEDERATED_AUTH_SESSION_ID ON IDN_FED_AUTH_SESSION_MAPPING (SESSION_ID);
  
  -- IDN_REMOTE_FETCH_REVISIONS --
  CREATE INDEX IDX_REMOTE_FETCH_REVISION_CONFIG_ID ON IDN_REMOTE_FETCH_REVISIONS (CONFIG_ID);
  
  -- IDN_CORS_ASSOCIATION --
  CREATE INDEX IDX_CORS_SP_APP_ID ON IDN_CORS_ASSOCIATION (SP_APP_ID);
  
  -- IDN_CORS_ASSOCIATION --
  CREATE INDEX IDX_CORS_ORIGIN_ID ON IDN_CORS_ASSOCIATION (IDN_CORS_ORIGIN_ID);
  