text: --- Start of tables that need to be modified ------
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[IDN_OAUTH_CONSUMER_APPS]') AND TYPE IN (N'U'))
  CREATE TABLE IDN_OAUTH_CONSUMER_APPS (
    ID INTEGER IDENTITY(1,1),
    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(2048),
    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)
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[IDN_OAUTH2_SCOPE]') AND TYPE IN (N'U'))
  CREATE TABLE IDN_OAUTH2_SCOPE (
    SCOPE_ID INTEGER IDENTITY (1,1),
    NAME VARCHAR(255) NOT NULL,
    DISPLAY_NAME VARCHAR(255) NOT NULL,
    DESCRIPTION VARCHAR(512),
    TENANT_ID INTEGER NOT NULL DEFAULT -1,
    PRIMARY KEY (SCOPE_ID)
  );
  
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[IDN_SCIM_GROUP]') AND TYPE IN (N'U'))
  CREATE TABLE IDN_SCIM_GROUP (
    ID INTEGER IDENTITY(1,1),
    TENANT_ID INTEGER NOT NULL,
    ROLE_NAME VARCHAR(255) NOT NULL,
    ATTR_NAME VARCHAR(1024) NOT NULL,
    ATTR_VALUE VARCHAR(1024),
    PRIMARY KEY (ID)
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[IDN_STS_STORE]') AND TYPE IN (N'U'))
  CREATE TABLE IDN_STS_STORE (
    ID INTEGER IDENTITY(1,1),
    TOKEN_ID VARCHAR(255) NOT NULL,
    TOKEN_CONTENT VARBINARY(MAX) NOT NULL,
    CREATE_DATE DATETIME NOT NULL,
    EXPIRE_DATE DATETIME NOT NULL,
    STATE INTEGER DEFAULT 0,
    PRIMARY KEY (ID)
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[SP_APP]') AND TYPE IN (N'U'))
  CREATE TABLE SP_APP (
    ID INTEGER NOT NULL IDENTITY (1,1),
    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',
    PRIMARY KEY (ID),
    CONSTRAINT APPLICATION_NAME_CONSTRAINT UNIQUE(APP_NAME, TENANT_ID)
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[SP_METADATA]') AND TYPE IN (N'U'))
  CREATE TABLE SP_METADATA (
    ID INTEGER IDENTITY (1,1),
    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)
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[SP_INBOUND_AUTH]') AND TYPE IN (N'U'))
  CREATE TABLE SP_INBOUND_AUTH (
    ID INTEGER NOT NULL IDENTITY (1,1),
    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),
    CONSTRAINT APPLICATION_ID_CONSTRAINT FOREIGN KEY (APP_ID) REFERENCES SP_APP (ID)
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[SP_AUTH_STEP]') AND TYPE IN (N'U'))
  CREATE TABLE SP_AUTH_STEP (
    ID INTEGER NOT NULL IDENTITY(1,1),
    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),
    CONSTRAINT APPLICATION_ID_CONSTRAINT_STEP FOREIGN KEY (APP_ID) REFERENCES SP_APP (ID) 
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[SP_CLAIM_DIALECT]') AND TYPE IN (N'U'))
  CREATE TABLE SP_CLAIM_DIALECT (
    ID INTEGER NOT NULL IDENTITY (1,1),
    TENANT_ID INTEGER NOT NULL,
    SP_DIALECT VARCHAR (512) NOT NULL,
    APP_ID INTEGER NOT NULL,
    PRIMARY KEY (ID),
    CONSTRAINT DIALECTID_APPID_CONSTRAINT FOREIGN KEY (APP_ID) REFERENCES SP_APP (ID) 
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[SP_CLAIM_MAPPING]') AND TYPE IN (N'U'))
  CREATE TABLE SP_CLAIM_MAPPING (
    ID INTEGER NOT NULL IDENTITY (1,1),
    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),
    CONSTRAINT CLAIMID_APPID_CONSTRAINT FOREIGN KEY (APP_ID) REFERENCES SP_APP (ID) 
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[SP_ROLE_MAPPING]') AND TYPE IN (N'U'))
  CREATE TABLE SP_ROLE_MAPPING (
    ID INTEGER NOT NULL IDENTITY (1,1),
    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),
    CONSTRAINT ROLEID_APPID_CONSTRAINT FOREIGN KEY (APP_ID) REFERENCES SP_APP (ID) 
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[SP_REQ_PATH_AUTHENTICATOR]') AND TYPE IN (N'U'))
  CREATE TABLE SP_REQ_PATH_AUTHENTICATOR (
    ID INTEGER NOT NULL IDENTITY (1,1),
    TENANT_ID INTEGER NOT NULL,
    AUTHENTICATOR_NAME VARCHAR (255) NOT NULL ,
    APP_ID INTEGER NOT NULL,
    PRIMARY KEY (ID),
    CONSTRAINT REQ_AUTH_APPID_CONSTRAINT FOREIGN KEY (APP_ID) REFERENCES SP_APP (ID) 
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[SP_PROVISIONING_CONNECTOR]') AND TYPE IN (N'U'))
  CREATE TABLE SP_PROVISIONING_CONNECTOR (
    ID INTEGER NOT NULL IDENTITY (1,1),
    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),
    CONSTRAINT PRO_CONNECTOR_APPID_CONSTRAINT FOREIGN KEY (APP_ID) REFERENCES SP_APP (ID) 
  );
  
  IF NOT EXISTS(SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[SP_AUTH_SCRIPT]') AND TYPE IN (N'U'))
  CREATE TABLE SP_AUTH_SCRIPT (
    ID         INTEGER IDENTITY (1,1) NOT NULL,
    TENANT_ID  INTEGER          NOT NULL,
    APP_ID     INTEGER          NOT NULL,
    TYPE       VARCHAR(255)     NOT NULL,
    CONTENT    VARBINARY(MAX)    DEFAULT NULL,
    IS_ENABLED CHAR(1) NOT NULL DEFAULT '0',
    PRIMARY KEY (ID)
  );
  
  IF NOT EXISTS(SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[SP_TEMPLATE]') AND TYPE IN (N'U'))
  CREATE TABLE SP_TEMPLATE (
    ID          INTEGER NOT NULL IDENTITY (1,1),
    TENANT_ID  INTEGER  NOT NULL,
    NAME VARCHAR(255) NOT NULL,
    DESCRIPTION VARCHAR(1023),
    CONTENT VARBINARY(MAX) DEFAULT NULL,
    PRIMARY KEY (ID),
    CONSTRAINT SP_TEMPLATE_CONSTRAINT UNIQUE (TENANT_ID, NAME)
  );
  
  IF NOT EXISTS(SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[IDN_AUTH_WAIT_STATUS]') AND TYPE IN (N'U'))
  CREATE TABLE IDN_AUTH_WAIT_STATUS (
    ID              INTEGER IDENTITY (1,1)      NOT NULL,
    TENANT_ID       INTEGER                NOT NULL,
    LONG_WAIT_KEY   VARCHAR(255)           NOT NULL,
    WAIT_STATUS     CHAR(1) NOT NULL DEFAULT '1',
    TIME_CREATED    DATETIME,
    EXPIRE_TIME     DATETIME,
    PRIMARY KEY (ID),
    CONSTRAINT IDN_AUTH_WAIT_STATUS_KEY UNIQUE (LONG_WAIT_KEY)
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[IDP]') AND TYPE IN (N'U'))
  CREATE TABLE IDP (
    ID INTEGER IDENTITY (1,1),
    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 VARBINARY(MAX),
    CERTIFICATE VARBINARY(MAX),
    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',
    PRIMARY KEY (ID),
    DISPLAY_NAME VARCHAR(255),
    UNIQUE (TENANT_ID, NAME)
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[IDP_ROLE]') AND TYPE IN (N'U'))
  CREATE TABLE IDP_ROLE (
    ID INTEGER IDENTITY (1,1),
    IDP_ID INTEGER,
    TENANT_ID INTEGER,
    ROLE VARCHAR(254),
    PRIMARY KEY (ID),
    UNIQUE (IDP_ID, ROLE),
    FOREIGN KEY (IDP_ID) REFERENCES IDP(ID) 
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[IDP_ROLE_MAPPING]') AND TYPE IN (N'U'))
  CREATE TABLE IDP_ROLE_MAPPING (
    ID INTEGER IDENTITY (1,1),
    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) 
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[IDP_CLAIM]') AND TYPE IN (N'U'))
  CREATE TABLE IDP_CLAIM (
    ID INTEGER IDENTITY (1,1),
    IDP_ID INTEGER,
    TENANT_ID INTEGER,
    CLAIM VARCHAR(254),
    PRIMARY KEY (ID),
    UNIQUE (IDP_ID, CLAIM),
    FOREIGN KEY (IDP_ID) REFERENCES IDP(ID) 
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[IDP_CLAIM_MAPPING]') AND TYPE IN (N'U'))
  CREATE TABLE IDP_CLAIM_MAPPING (
    ID INTEGER IDENTITY (1,1),
    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) 
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[IDP_AUTHENTICATOR]') AND TYPE IN (N'U'))
  CREATE TABLE IDP_AUTHENTICATOR (
    ID INTEGER IDENTITY (1,1),
    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) 
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[IDP_METADATA]') AND TYPE IN (N'U'))
  CREATE TABLE IDP_METADATA (
    ID INTEGER IDENTITY (1,1),
    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) 
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[IDP_AUTHENTICATOR_PROPERTY]') AND TYPE IN (N'U'))
  CREATE TABLE IDP_AUTHENTICATOR_PROPERTY (
    ID INTEGER IDENTITY (1,1),
    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) 
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[IDP_PROVISIONING_CONFIG]') AND TYPE IN (N'U'))
  CREATE TABLE IDP_PROVISIONING_CONFIG (
    ID INTEGER IDENTITY (1,1),
    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) 
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[IDP_PROV_CONFIG_PROPERTY]') AND TYPE IN (N'U'))
  CREATE TABLE IDP_PROV_CONFIG_PROPERTY (
    ID INTEGER IDENTITY (1,1),
    TENANT_ID INTEGER,
    PROVISIONING_CONFIG_ID INTEGER,
    PROPERTY_KEY VARCHAR(255) NOT NULL,
    PROPERTY_VALUE VARCHAR(2048),
    PROPERTY_BLOB_VALUE VARBINARY(MAX),
    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) 
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[IDP_PROVISIONING_ENTITY]') AND TYPE IN (N'U'))
  CREATE TABLE IDP_PROVISIONING_ENTITY (
    ID INTEGER IDENTITY (1,1),
    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) 
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[IDP_LOCAL_CLAIM]') AND TYPE IN (N'U'))
  CREATE TABLE IDP_LOCAL_CLAIM (
    ID INTEGER IDENTITY (1,1),
    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) 
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[IDN_ASSOCIATED_ID]') AND TYPE IN (N'U'))
  CREATE TABLE IDN_ASSOCIATED_ID (
    ID INTEGER IDENTITY (1,1),
    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,
    PRIMARY KEY (ID),
    UNIQUE(IDP_USER_ID, TENANT_ID, IDP_ID),
    FOREIGN KEY (IDP_ID) REFERENCES IDP(ID)
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[WF_WORKFLOW_ASSOCIATION]') AND TYPE IN (N'U'))
  CREATE TABLE WF_WORKFLOW_ASSOCIATION(
    ID INTEGER NOT NULL IDENTITY (1,1),
    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)
  );
  
   IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[IDN_PASSWORD_HISTORY_DATA]') AND TYPE IN (N'U'))
  CREATE TABLE IDN_PASSWORD_HISTORY_DATA (
    ID INTEGER NOT NULL IDENTITY (1,1) ,
    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 DATETIME NOT NULL,
    PRIMARY KEY (ID),
    UNIQUE (USER_NAME,USER_DOMAIN,TENANT_ID,SALT_VALUE,HASH),
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[IDN_CLAIM_DIALECT]') AND TYPE IN (N'U'))
  CREATE TABLE IDN_CLAIM_DIALECT (
    ID INTEGER NOT NULL IDENTITY (1,1) ,
    DIALECT_URI VARCHAR (255) NOT NULL,
    TENANT_ID INTEGER NOT NULL,
    PRIMARY KEY (ID),
    CONSTRAINT DIALECT_URI_CONSTRAINT UNIQUE (DIALECT_URI, TENANT_ID)
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[IDN_CLAIM]') AND TYPE IN (N'U'))
  CREATE TABLE IDN_CLAIM (
    ID INTEGER NOT NULL IDENTITY (1,1) ,
    DIALECT_ID INTEGER,
    CLAIM_URI VARCHAR (255) NOT NULL,
    TENANT_ID INTEGER NOT NULL,
    PRIMARY KEY (ID),
    FOREIGN KEY (DIALECT_ID) REFERENCES IDN_CLAIM_DIALECT(ID) ,
    CONSTRAINT CLAIM_URI_CONSTRAINT UNIQUE (DIALECT_ID, CLAIM_URI, TENANT_ID)
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[IDN_CLAIM_MAPPED_ATTRIBUTE]') AND TYPE IN (N'U'))
  CREATE TABLE IDN_CLAIM_MAPPED_ATTRIBUTE (
    ID INTEGER NOT NULL IDENTITY (1,1) ,
    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),
    CONSTRAINT USER_STORE_DOMAIN_CONSTRAINT UNIQUE (LOCAL_CLAIM_ID, USER_STORE_DOMAIN_NAME, TENANT_ID)
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[IDN_CLAIM_PROPERTY]') AND TYPE IN (N'U'))
  CREATE TABLE IDN_CLAIM_PROPERTY (
    ID INTEGER NOT NULL IDENTITY (1,1) ,
    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) ,
    CONSTRAINT PROPERTY_NAME_CONSTRAINT UNIQUE (LOCAL_CLAIM_ID, PROPERTY_NAME, TENANT_ID)
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[IDN_CLAIM_MAPPING]') AND TYPE IN (N'U'))
  CREATE TABLE IDN_CLAIM_MAPPING (
    ID INTEGER NOT NULL IDENTITY (1,1) ,
    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) ,
    FOREIGN KEY (MAPPED_LOCAL_CLAIM_ID) REFERENCES IDN_CLAIM(ID),
    CONSTRAINT EXT_TO_LOC_MAPPING_CONSTRN UNIQUE (EXT_CLAIM_ID, TENANT_ID)
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[IDN_SAML2_ASSERTION_STORE]') AND TYPE IN (N'U'))
  CREATE TABLE IDN_SAML2_ASSERTION_STORE (
    ID INTEGER NOT NULL IDENTITY (1,1) ,
    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) ,
    ASSERTION VARBINARY(MAX) ,
    PRIMARY KEY (ID)
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[IDN_SAML2_ARTIFACT_STORE]') AND TYPE IN (N'U'))
  CREATE TABLE IDN_SAML2_ARTIFACT_STORE (
    ID INTEGER NOT NULL IDENTITY (1,1) ,
    SOURCE_ID VARCHAR(255) NOT NULL,
    MESSAGE_HANDLER VARCHAR(255) NOT NULL,
    AUTHN_REQ_DTO VARBINARY(MAX) NOT NULL,
    SESSION_ID VARCHAR(255) NOT NULL,
    INIT_TIMESTAMP DATETIME NOT NULL,
    EXP_TIMESTAMP DATETIME NOT NULL,
    ASSERTION_ID VARCHAR(255),
    PRIMARY KEY (ID)
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[IDN_OIDC_PROPERTY]') AND TYPE IN (N'U'))
  CREATE TABLE IDN_OIDC_PROPERTY (
    ID INTEGER NOT NULL IDENTITY(1,1) ,
    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) 
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[IDN_OIDC_REQ_OBJECT_REFERENCE]') AND TYPE IN (N'U'))
  CREATE TABLE IDN_OIDC_REQ_OBJECT_REFERENCE (
    ID INTEGER NOT NULL IDENTITY(1,1) ,
    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),
    FOREIGN KEY (TOKEN_ID) REFERENCES IDN_OAUTH2_ACCESS_TOKEN(TOKEN_ID),
    FOREIGN KEY (CODE_ID) REFERENCES IDN_OAUTH2_AUTHORIZATION_CODE(CODE_ID)
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[IDN_OIDC_REQ_OBJECT_CLAIMS]') AND TYPE IN (N'U'))
  CREATE TABLE IDN_OIDC_REQ_OBJECT_CLAIMS (
    ID INTEGER NOT NULL IDENTITY(1,1) ,
    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) 
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[IDN_OIDC_REQ_OBJ_CLAIM_VALUES]') AND TYPE IN (N'U'))
  CREATE TABLE IDN_OIDC_REQ_OBJ_CLAIM_VALUES (
    ID INTEGER NOT NULL IDENTITY(1,1) ,
    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) 
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[IDN_CERTIFICATE]') AND TYPE IN (N'U'))
  CREATE TABLE IDN_CERTIFICATE (
               ID INTEGER IDENTITY(1,1) ,
               NAME VARCHAR(100),
               CERTIFICATE_IN_PEM VARBINARY(MAX),
               TENANT_ID INTEGER DEFAULT 0,
               PRIMARY KEY(ID),
               CONSTRAINT CERTIFICATE_UNIQUE_KEY UNIQUE (NAME, TENANT_ID)
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[IDN_OIDC_SCOPE]') AND TYPE IN (N'U'))
  CREATE TABLE IDN_OIDC_SCOPE  (
    ID INTEGER IDENTITY(1,1) ,
    NAME VARCHAR(255),
    TENANT_ID INTEGER DEFAULT -1,
    PRIMARY KEY (ID)
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[IDN_OIDC_SCOPE_CLAIM_MAPPING]') AND TYPE IN (N'U'))
  CREATE TABLE IDN_OIDC_SCOPE_CLAIM_MAPPING (
    ID INTEGER IDENTITY(1,1) ,
    SCOPE_ID INTEGER ,
    EXTERNAL_CLAIM_ID INTEGER ,
    PRIMARY KEY (ID),
    FOREIGN KEY (SCOPE_ID) REFERENCES  IDN_OIDC_SCOPE(ID),
    FOREIGN KEY (EXTERNAL_CLAIM_ID) REFERENCES  IDN_CLAIM(ID)
  );
  
  IF NOT EXISTS ( SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[CM_PII_CATEGORY]') AND TYPE IN (N'U'))
  CREATE TABLE CM_PII_CATEGORY (
    ID           INTEGER      NOT NULL  IDENTITY (1,1),
    NAME         VARCHAR(255) NOT NULL,
    DESCRIPTION  VARCHAR(1023),
    DISPLAY_NAME VARCHAR(255),
    IS_SENSITIVE INTEGER      NOT NULL,
    TENANT_ID    INTEGER DEFAULT '-1234',
    CONSTRAINT CM_PII_CATEGORY_CNT UNIQUE (NAME, TENANT_ID),
    PRIMARY KEY (ID)
  );
  
  IF NOT EXISTS ( SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[CM_PURPOSE]') AND TYPE IN (N'U'))
  CREATE TABLE CM_PURPOSE (
    ID            INTEGER      NOT NULL  IDENTITY (1,1),
    NAME          VARCHAR(255) NOT NULL,
    DESCRIPTION   VARCHAR(1023),
    PURPOSE_GROUP VARCHAR(255) NOT NULL,
    GROUP_TYPE    VARCHAR(255) NOT NULL,
    TENANT_ID     INTEGER DEFAULT '-1234',
    CONSTRAINT CM_PURPOSE_CNT UNIQUE (NAME, TENANT_ID, PURPOSE_GROUP, GROUP_TYPE),
    PRIMARY KEY (ID)
  );
  
  IF NOT EXISTS ( SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[CM_PURPOSE_CATEGORY]') AND TYPE IN (N'U'))
  CREATE TABLE CM_PURPOSE_CATEGORY (
    ID          INTEGER      NOT NULL  IDENTITY(1,1),
    NAME        VARCHAR(255) NOT NULL,
    DESCRIPTION VARCHAR(1023),
    TENANT_ID   INTEGER DEFAULT '-1234',
    CONSTRAINT CM_PURPOSE_CATEGORY_CNT UNIQUE (NAME, TENANT_ID),
    PRIMARY KEY (ID)
  );
  
  IF NOT EXISTS ( SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[CM_RECEIPT_SP_ASSOC]') AND TYPE IN (N'U'))
  CREATE TABLE CM_RECEIPT_SP_ASSOC (
    ID                 INTEGER      NOT NULL  IDENTITY (1,1),
    CONSENT_RECEIPT_ID VARCHAR(255) NOT NULL,
    SP_NAME            VARCHAR(255) NOT NULL,
    SP_DISPLAY_NAME    VARCHAR(255),
    SP_DESCRIPTION     VARCHAR(255),
    SP_TENANT_ID       INTEGER DEFAULT '-1234',
    CONSTRAINT CM_RECEIPT_SP_ASSOC_CNT UNIQUE (CONSENT_RECEIPT_ID, SP_NAME, SP_TENANT_ID),
    FOREIGN KEY (CONSENT_RECEIPT_ID) REFERENCES CM_RECEIPT (CONSENT_RECEIPT_ID),
    PRIMARY KEY (ID)
  );
  
  IF NOT EXISTS ( SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[CM_SP_PURPOSE_ASSOC]') AND TYPE IN (N'U'))
  CREATE TABLE CM_SP_PURPOSE_ASSOC (
    ID                     INTEGER      NOT NULL  IDENTITY (1,1),
    RECEIPT_SP_ASSOC       INTEGER      NOT NULL,
    PURPOSE_ID             INTEGER      NOT NULL,
    CONSENT_TYPE           VARCHAR(255) NOT NULL,
    IS_PRIMARY_PURPOSE     INTEGER      NOT NULL,
    TERMINATION            VARCHAR(255) NOT NULL,
    THIRD_PARTY_DISCLOSURE INTEGER      NOT NULL,
    THIRD_PARTY_NAME       VARCHAR(255),
    CONSTRAINT CM_SP_PURPOSE_ASSOC_CNT UNIQUE (RECEIPT_SP_ASSOC, PURPOSE_ID),
    FOREIGN KEY (RECEIPT_SP_ASSOC) REFERENCES CM_RECEIPT_SP_ASSOC (ID),
    FOREIGN KEY (PURPOSE_ID) REFERENCES CM_PURPOSE (ID),
    PRIMARY KEY (ID)
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AM_SUBSCRIBER]') AND TYPE IN (N'U'))
  CREATE TABLE AM_SUBSCRIBER (
      SUBSCRIBER_ID INTEGER IDENTITY(1,1),
      USER_ID VARCHAR(50) NOT NULL,
      TENANT_ID INTEGER NOT NULL,
      EMAIL_ADDRESS VARCHAR(256) NULL,
      DATE_SUBSCRIBED DATETIME NOT NULL,
      CREATED_BY VARCHAR(100),
      CREATED_TIME DATETIME,
      UPDATED_BY VARCHAR(100),
      UPDATED_TIME DATETIME,
      PRIMARY KEY (SUBSCRIBER_ID),
      UNIQUE (TENANT_ID,USER_ID)
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AM_APPLICATION]') AND TYPE IN (N'U'))
  CREATE TABLE AM_APPLICATION (
      APPLICATION_ID INTEGER IDENTITY(1,1),
      NAME VARCHAR(100) COLLATE Latin1_General_CS_AS,
      SUBSCRIBER_ID INTEGER,
      APPLICATION_TIER VARCHAR(50) DEFAULT 'Unlimited',
      CALLBACK_URL VARCHAR(512),
      DESCRIPTION VARCHAR(512),
      APPLICATION_STATUS VARCHAR(50) DEFAULT 'APPROVED',
      GROUP_ID VARCHAR(100),
      CREATED_BY VARCHAR(100),
      CREATED_TIME DATETIME,
      UPDATED_BY VARCHAR(100),
      UPDATED_TIME DATETIME,
      UUID VARCHAR(256),
      TOKEN_TYPE VARCHAR(10),
      FOREIGN KEY(SUBSCRIBER_ID) REFERENCES AM_SUBSCRIBER(SUBSCRIBER_ID),
      PRIMARY KEY(APPLICATION_ID),
      UNIQUE (NAME,SUBSCRIBER_ID),
      UNIQUE (UUID)
  );
  
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AM_API]') AND TYPE IN (N'U'))
  CREATE TABLE AM_API (
      API_ID INTEGER IDENTITY(1,1),
      API_PROVIDER VARCHAR(200),
      API_NAME VARCHAR(200),
      API_VERSION VARCHAR(30),
      CONTEXT VARCHAR(256),
      CONTEXT_TEMPLATE VARCHAR(256),
      API_TIER VARCHAR(256),
      API_TYPE VARCHAR(10),
      CREATED_BY VARCHAR(100),
      CREATED_TIME DATETIME,
      UPDATED_BY VARCHAR(100),
      UPDATED_TIME DATETIME,
      REVISIONS_CREATED INTEGER DEFAULT 0,
      PRIMARY KEY(API_ID),
      UNIQUE (API_PROVIDER,API_NAME,API_VERSION)
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AM_API_REVISION_METADATA]') AND TYPE IN (N'U'))
  
  CREATE TABLE AM_API_REVISION_METADATA (
      API_UUID VARCHAR(64),
      REVISION_UUID VARCHAR(64),
      API_TIER VARCHAR(128),
      UNIQUE (API_UUID,REVISION_UUID)
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AM_API_URL_MAPPING]') AND TYPE IN (N'U'))
  CREATE TABLE AM_API_URL_MAPPING (
      URL_MAPPING_ID INTEGER IDENTITY(1,1),
      API_ID INTEGER NOT NULL,
      HTTP_METHOD VARCHAR(20) NULL,
      AUTH_SCHEME VARCHAR(50) NULL,
      URL_PATTERN VARCHAR(512) NULL,
      THROTTLING_TIER varchar(512) DEFAULT NULL,
      MEDIATION_SCRIPT VARBINARY(MAX),
      PRIMARY KEY (URL_MAPPING_ID)
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AM_API_PRODUCT_MAPPING]') AND TYPE IN (N'U'))
  CREATE TABLE AM_API_PRODUCT_MAPPING (
    API_PRODUCT_MAPPING_ID INTEGER IDENTITY(1,1),
    API_ID INTEGER,
    URL_MAPPING_ID INTEGER,
    FOREIGN KEY (API_ID) REFERENCES AM_API(API_ID),
    FOREIGN KEY (URL_MAPPING_ID) REFERENCES AM_API_URL_MAPPING(URL_MAPPING_ID),
    PRIMARY KEY(API_PRODUCT_MAPPING_ID)
  );
  
  -- TODO: Have to add ON UPDATE CASCADE for the FOREIGN KEY(SUBSCRIPTION_ID) relation
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AM_SUBSCRIPTION]') AND TYPE IN (N'U'))
  CREATE TABLE AM_SUBSCRIPTION (
      SUBSCRIPTION_ID INTEGER IDENTITY(1,1),
      TIER_ID VARCHAR(50),
      TIER_ID_PENDING VARCHAR(50),
      API_ID INTEGER,
      LAST_ACCESSED DATETIME NULL,
      APPLICATION_ID INTEGER,
      SUB_STATUS VARCHAR(50),
      SUBS_CREATE_STATE VARCHAR(50) DEFAULT 'SUBSCRIBE',
      CREATED_BY VARCHAR(100),
      CREATED_TIME DATETIME,
      UPDATED_BY VARCHAR(100),
      UPDATED_TIME DATETIME,
      UUID VARCHAR(256),
      FOREIGN KEY(APPLICATION_ID) REFERENCES AM_APPLICATION(APPLICATION_ID),
      FOREIGN KEY(API_ID) REFERENCES AM_API(API_ID),
      PRIMARY KEY (SUBSCRIPTION_ID),
      UNIQUE (UUID)
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AM_APPLICATION_REGISTRATION]') AND TYPE IN (N'U'))
  CREATE TABLE AM_APPLICATION_REGISTRATION (
      REG_ID INTEGER IDENTITY(1,1),
      SUBSCRIBER_ID INTEGER,
      WF_REF VARCHAR(255) NOT NULL,
      APP_ID INTEGER,
      TOKEN_TYPE VARCHAR(30),
      TOKEN_SCOPE VARCHAR(1500) DEFAULT 'default',
      INPUTS VARCHAR(1000),
      ALLOWED_DOMAINS VARCHAR(256),
      VALIDITY_PERIOD BIGINT,
      KEY_MANAGER VARCHAR(255) NOT NULL,
      UNIQUE (SUBSCRIBER_ID,APP_ID,TOKEN_TYPE,KEY_MANAGER),
      FOREIGN KEY(SUBSCRIBER_ID) REFERENCES AM_SUBSCRIBER(SUBSCRIBER_ID) ,
      FOREIGN KEY(APP_ID) REFERENCES AM_APPLICATION(APPLICATION_ID),
      PRIMARY KEY (REG_ID)
  );
  
  -- TODO: Have to add ON UPDATE CASCADE for the FOREIGN KEY(API_ID) relation
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AM_API_LC_EVENT]') AND TYPE IN (N'U'))
  CREATE TABLE AM_API_LC_EVENT (
      EVENT_ID INTEGER IDENTITY(1,1),
      API_ID INTEGER NOT NULL,
      PREVIOUS_STATE VARCHAR(50),
      NEW_STATE VARCHAR(50) NOT NULL,
      USER_ID VARCHAR(50) NOT NULL,
      TENANT_ID INTEGER NOT NULL,
      EVENT_DATE DATETIME NOT NULL,
      FOREIGN KEY(API_ID) REFERENCES AM_API(API_ID),
      PRIMARY KEY (EVENT_ID)
  );
  
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AM_TIER_PERMISSIONS]') AND TYPE IN (N'U'))
  CREATE TABLE AM_TIER_PERMISSIONS (
      TIER_PERMISSIONS_ID INTEGER IDENTITY(1,1),
      TIER VARCHAR(50) NOT NULL,
      PERMISSIONS_TYPE VARCHAR(50) NOT NULL,
      ROLES VARCHAR(512) NOT NULL,
      TENANT_ID INTEGER NOT NULL,
      PRIMARY KEY(TIER_PERMISSIONS_ID)
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AM_EXTERNAL_STORES]') AND TYPE IN (N'U'))
  CREATE TABLE AM_EXTERNAL_STORES (
      APISTORE_ID INTEGER IDENTITY(1,1),
      API_ID INTEGER,
      STORE_ID VARCHAR(255) NOT NULL,
      STORE_DISPLAY_NAME VARCHAR(255) NOT NULL,
      STORE_ENDPOINT VARCHAR(255) NOT NULL,
      STORE_TYPE VARCHAR(255) NOT NULL,
      LAST_UPDATED_TIME DATETIME,
      FOREIGN KEY(API_ID) REFERENCES AM_API(API_ID),
      PRIMARY KEY (APISTORE_ID)
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AM_WORKFLOWS]') AND TYPE IN (N'U'))
  CREATE TABLE AM_WORKFLOWS(
      WF_ID INTEGER IDENTITY(1,1),
      WF_REFERENCE VARCHAR(255) NOT NULL,
      WF_TYPE VARCHAR(255) NOT NULL,
      WF_STATUS VARCHAR(255) NOT NULL,
      WF_CREATED_TIME DATETIME DEFAULT GETDATE(),
      WF_UPDATED_TIME DATETIME DEFAULT GETDATE(),
      WF_STATUS_DESC VARCHAR(1000),
      TENANT_ID INTEGER,
      TENANT_DOMAIN VARCHAR(255),
      WF_EXTERNAL_REFERENCE VARCHAR(255) NOT NULL UNIQUE,
      PRIMARY KEY (WF_ID)
  );
  
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AM_ALERT_TYPES]') AND TYPE IN (N'U'))
  CREATE TABLE  AM_ALERT_TYPES (
              ALERT_TYPE_ID INTEGER NOT NULL IDENTITY (1,1),
              ALERT_TYPE_NAME VARCHAR(255) NOT NULL ,
              STAKE_HOLDER VARCHAR(10) NOT NULL,
              PRIMARY KEY (ALERT_TYPE_ID)
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AM_ALERT_EMAILLIST]') AND TYPE IN (N'U'))
  CREATE TABLE AM_ALERT_EMAILLIST (
         EMAIL_LIST_ID INTEGER NOT NULL IDENTITY (1,1),
               USER_NAME VARCHAR(255) NOT NULL ,
         STAKE_HOLDER VARCHAR(100) NOT NULL ,
         CONSTRAINT AM_ALERT_EMAILLIST_CONST UNIQUE (EMAIL_LIST_ID,USER_NAME,STAKE_HOLDER),
               PRIMARY KEY (EMAIL_LIST_ID)
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AM_POLICY_SUBSCRIPTION]') AND TYPE IN (N'U'))
  CREATE TABLE AM_POLICY_SUBSCRIPTION (
              POLICY_ID INTEGER IDENTITY(1,1),
              NAME VARCHAR(512) NOT NULL,
              DISPLAY_NAME VARCHAR(512) NULL DEFAULT NULL,
              TENANT_ID INTEGER NOT NULL,
              DESCRIPTION VARCHAR(1024) NULL DEFAULT NULL,
              QUOTA_TYPE VARCHAR(25) NOT NULL,
              QUOTA INTEGER NOT NULL,
              QUOTA_UNIT VARCHAR(10) NULL,
              UNIT_TIME INTEGER NOT NULL,
              TIME_UNIT VARCHAR(25) NOT NULL,
              RATE_LIMIT_COUNT INTEGER NULL DEFAULT NULL,
              RATE_LIMIT_TIME_UNIT VARCHAR(25) NULL DEFAULT NULL,
              IS_DEPLOYED BIT NOT NULL DEFAULT 0,
        CUSTOM_ATTRIBUTES VARBINARY(MAX) DEFAULT NULL,
              STOP_ON_QUOTA_REACH BIT NOT NULL DEFAULT 0,
              BILLING_PLAN VARCHAR(20) NOT NULL,
              UUID VARCHAR(256),
              MONETIZATION_PLAN VARCHAR(25) NULL DEFAULT NULL,
              FIXED_RATE VARCHAR(15) NULL DEFAULT NULL,
              BILLING_CYCLE VARCHAR(15) NULL DEFAULT NULL,
              PRICE_PER_REQUEST VARCHAR(15) NULL DEFAULT NULL,
              CURRENCY VARCHAR(15) NULL DEFAULT NULL,
              PRIMARY KEY (POLICY_ID),
              UNIQUE (NAME, TENANT_ID),
              UNIQUE (UUID)
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AM_POLICY_APPLICATION]') AND TYPE IN (N'U'))
  CREATE TABLE AM_POLICY_APPLICATION (
              POLICY_ID INTEGER IDENTITY(1,1),
              NAME VARCHAR(512) NOT NULL,
              DISPLAY_NAME VARCHAR(512) NULL DEFAULT NULL,
              TENANT_ID INTEGER NOT NULL,
              DESCRIPTION VARCHAR(1024) NULL DEFAULT NULL,
              QUOTA_TYPE VARCHAR(25) NOT NULL,
              QUOTA INTEGER NOT NULL,
              QUOTA_UNIT VARCHAR(10) NULL DEFAULT NULL,
              UNIT_TIME INTEGER NOT NULL,
              TIME_UNIT VARCHAR(25) NOT NULL,
              IS_DEPLOYED BIT NOT NULL DEFAULT 0,
        CUSTOM_ATTRIBUTES VARBINARY(MAX) DEFAULT NULL,
              UUID VARCHAR(256),
              PRIMARY KEY (POLICY_ID),
              UNIQUE  (NAME, TENANT_ID),
              UNIQUE (UUID)
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AM_POLICY_HARD_THROTTLING]') AND TYPE IN (N'U'))
  CREATE TABLE AM_POLICY_HARD_THROTTLING (
              POLICY_ID INTEGER IDENTITY(1,1),
              NAME VARCHAR(512) NOT NULL,
              TENANT_ID INTEGER NOT NULL,
              DESCRIPTION VARCHAR(1024) NULL DEFAULT NULL,
              QUOTA_TYPE VARCHAR(25) NOT NULL,
              QUOTA INTEGER NOT NULL,
              QUOTA_UNIT VARCHAR(10) NULL DEFAULT NULL,
              UNIT_TIME INTEGER NOT NULL,
              TIME_UNIT VARCHAR(25) NOT NULL,
              IS_DEPLOYED BIT NOT NULL DEFAULT 0,
              PRIMARY KEY (POLICY_ID),
              UNIQUE  (NAME, TENANT_ID)
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AM_API_THROTTLE_POLICY]') AND TYPE IN (N'U'))
  CREATE TABLE AM_API_THROTTLE_POLICY (
              POLICY_ID INTEGER IDENTITY(1,1),
              NAME VARCHAR(512) NOT NULL,
              DISPLAY_NAME VARCHAR(512) NULL DEFAULT NULL,
              TENANT_ID INTEGER NOT NULL,
              DESCRIPTION VARCHAR (1024),
              DEFAULT_QUOTA_TYPE VARCHAR(25) NOT NULL,
              DEFAULT_QUOTA INTEGER NOT NULL,
              DEFAULT_QUOTA_UNIT VARCHAR(10) NULL,
              DEFAULT_UNIT_TIME INTEGER NOT NULL,
              DEFAULT_TIME_UNIT VARCHAR(25) NOT NULL,
              APPLICABLE_LEVEL VARCHAR(25) NOT NULL,
              IS_DEPLOYED BIT NOT NULL DEFAULT 0,
              UUID VARCHAR(256),
              PRIMARY KEY (POLICY_ID),
              UNIQUE  (NAME, TENANT_ID),
              UNIQUE (UUID)
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AM_CONDITION_GROUP]') AND TYPE IN (N'U'))
  CREATE TABLE AM_CONDITION_GROUP (
              CONDITION_GROUP_ID INTEGER IDENTITY(1,1),
              POLICY_ID INTEGER NOT NULL,
              QUOTA_TYPE VARCHAR(25),
              QUOTA INTEGER NOT NULL,
              QUOTA_UNIT VARCHAR(10) NULL DEFAULT NULL,
              UNIT_TIME INTEGER NOT NULL,
              TIME_UNIT VARCHAR(25) NOT NULL,
              DESCRIPTION VARCHAR (1024) NULL DEFAULT NULL,
              PRIMARY KEY (CONDITION_GROUP_ID),
              FOREIGN KEY (POLICY_ID) REFERENCES AM_API_THROTTLE_POLICY(POLICY_ID) 
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AM_QUERY_PARAMETER_CONDITION]') AND TYPE IN (N'U'))
  CREATE TABLE AM_QUERY_PARAMETER_CONDITION (
              QUERY_PARAMETER_ID INTEGER IDENTITY(1,1),
              CONDITION_GROUP_ID INTEGER NOT NULL,
              PARAMETER_NAME VARCHAR(255) DEFAULT NULL,
              PARAMETER_VALUE VARCHAR(255) DEFAULT NULL,
          IS_PARAM_MAPPING BIT DEFAULT 1,
              PRIMARY KEY (QUERY_PARAMETER_ID),
              FOREIGN KEY (CONDITION_GROUP_ID) REFERENCES AM_CONDITION_GROUP(CONDITION_GROUP_ID) 
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AM_HEADER_FIELD_CONDITION]') AND TYPE IN (N'U'))
  CREATE TABLE AM_HEADER_FIELD_CONDITION (
              HEADER_FIELD_ID INTEGER IDENTITY(1,1),
              CONDITION_GROUP_ID INTEGER NOT NULL,
              HEADER_FIELD_NAME VARCHAR(255) DEFAULT NULL,
              HEADER_FIELD_VALUE VARCHAR(255) DEFAULT NULL,
          IS_HEADER_FIELD_MAPPING BIT DEFAULT 1,
              PRIMARY KEY (HEADER_FIELD_ID),
              FOREIGN KEY (CONDITION_GROUP_ID) REFERENCES AM_CONDITION_GROUP(CONDITION_GROUP_ID) 
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AM_JWT_CLAIM_CONDITION]') AND TYPE IN (N'U'))
  CREATE TABLE AM_JWT_CLAIM_CONDITION (
              JWT_CLAIM_ID INTEGER IDENTITY(1,1),
              CONDITION_GROUP_ID INTEGER NOT NULL,
              CLAIM_URI VARCHAR(512) DEFAULT NULL,
              CLAIM_ATTRIB VARCHAR(1024) DEFAULT NULL,
        IS_CLAIM_MAPPING BIT DEFAULT 1,
              PRIMARY KEY (JWT_CLAIM_ID),
              FOREIGN KEY (CONDITION_GROUP_ID) REFERENCES AM_CONDITION_GROUP(CONDITION_GROUP_ID) 
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AM_IP_CONDITION]') AND TYPE IN (N'U'))
  CREATE TABLE AM_IP_CONDITION (
    AM_IP_CONDITION_ID INTEGER IDENTITY(1,1),
    STARTING_IP VARCHAR(45) NULL,
    ENDING_IP VARCHAR(45) NULL,
    SPECIFIC_IP VARCHAR(45) NULL,
    WITHIN_IP_RANGE BIT DEFAULT 1,
    CONDITION_GROUP_ID INT NULL,
    PRIMARY KEY (AM_IP_CONDITION_ID),
    FOREIGN KEY (CONDITION_GROUP_ID)
      REFERENCES AM_CONDITION_GROUP (CONDITION_GROUP_ID));
  
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AM_POLICY_GLOBAL]') AND TYPE IN (N'U'))
  CREATE TABLE AM_POLICY_GLOBAL (
              POLICY_ID INTEGER IDENTITY(1,1),
              NAME VARCHAR(512) NOT NULL,
              KEY_TEMPLATE VARCHAR(512) NOT NULL,
              TENANT_ID INTEGER NOT NULL,
              DESCRIPTION VARCHAR(1024) NULL DEFAULT NULL,
              SIDDHI_QUERY VARBINARY(MAX) DEFAULT NULL,
              IS_DEPLOYED BIT NOT NULL DEFAULT 0,
              UUID VARCHAR(256),
              PRIMARY KEY (POLICY_ID),
              UNIQUE (UUID)
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AM_THROTTLE_TIER_PERMISSIONS]') AND TYPE IN (N'U'))
  CREATE TABLE AM_THROTTLE_TIER_PERMISSIONS (
    THROTTLE_TIER_PERMISSIONS_ID INTEGER IDENTITY(1,1),
    TIER VARCHAR(50) NULL,
    PERMISSIONS_TYPE VARCHAR(50) NULL,
    ROLES VARCHAR(512) NULL,
    TENANT_ID INTEGER NULL,
    PRIMARY KEY (THROTTLE_TIER_PERMISSIONS_ID));
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AM_BLOCK_CONDITIONS]') AND TYPE IN (N'U'))
  CREATE TABLE AM_BLOCK_CONDITIONS (
    CONDITION_ID INTEGER IDENTITY(1,1),
    TYPE varchar(45) DEFAULT NULL,
    BLOCK_CONDITION varchar(512) DEFAULT NULL,
    ENABLED varchar(45) DEFAULT NULL,
    DOMAIN varchar(45) DEFAULT NULL,
    UUID VARCHAR(256),
    PRIMARY KEY (CONDITION_ID),
    UNIQUE (UUID)
  );
  
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AM_API_LC_PUBLISH_EVENTS]') AND TYPE IN (N'U'))
  CREATE TABLE AM_API_LC_PUBLISH_EVENTS (
      ID INTEGER NOT NULL IDENTITY (1,1),
      TENANT_DOMAIN VARCHAR(255) NOT NULL,
      API_ID VARCHAR(500) NOT NULL,
      EVENT_TIME DATETIME DEFAULT GETDATE(),
      PRIMARY KEY (ID)
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'AM_SYSTEM_APPS') AND TYPE IN (N'U'))
  CREATE TABLE AM_SYSTEM_APPS (
      ID INTEGER IDENTITY (1,1),
      NAME VARCHAR(50) NOT NULL,
      CONSUMER_KEY VARCHAR(512) NOT NULL,
      CONSUMER_SECRET VARCHAR(512) NOT NULL,
      CREATED_TIME DATETIME2(6) DEFAULT CURRENT_TIMESTAMP,
      UNIQUE (NAME),
      UNIQUE (CONSUMER_KEY),
      PRIMARY KEY (ID)
  );
  
  ---------- End of tables that need to be modified -----------------
  
  -- Start of IDN Tables --
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[IDN_BASE_TABLE]') AND TYPE IN (N'U'))
  CREATE TABLE IDN_BASE_TABLE (
    PRODUCT_NAME VARCHAR(20),
    PRIMARY KEY (PRODUCT_NAME)
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[IDN_OAUTH2_SCOPE_VALIDATORS]') AND TYPE IN (N'U'))
  CREATE TABLE 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) 
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[IDN_OAUTH1A_REQUEST_TOKEN]') AND TYPE IN (N'U'))
  CREATE TABLE IDN_OAUTH1A_REQUEST_TOKEN (
    REQUEST_TOKEN VARCHAR(512),
    REQUEST_TOKEN_SECRET VARCHAR(512),
    CONSUMER_KEY_ID INTEGER,
    CALLBACK_URL VARCHAR(2048),
    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)
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[IDN_OAUTH2_ACCESS_TOKEN]') AND TYPE IN (N'U'))
  CREATE TABLE 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 DATETIME,
    REFRESH_TOKEN_TIME_CREATED DATETIME,
    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,
    DCID VARCHAR(50) DEFAULT 'DC1',
    PRIMARY KEY (TOKEN_ID),
    FOREIGN KEY (CONSUMER_KEY_ID) REFERENCES IDN_OAUTH_CONSUMER_APPS(ID),
    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,DCID)
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[IDN_OAUTH2_ACCESS_TOKEN_AUDIT]') AND TYPE IN (N'U'))
  CREATE TABLE IDN_OAUTH2_ACCESS_TOKEN_AUDIT (
              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 DATETIME,
              REFRESH_TOKEN_TIME_CREATED DATETIME,
              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 DATETIME,
              IDP_ID INTEGER
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[IDN_OAUTH2_AUTHORIZATION_CODE]') AND TYPE IN (N'U'))
  CREATE TABLE IDN_OAUTH2_AUTHORIZATION_CODE (
    CODE_ID VARCHAR (255),
    AUTHORIZATION_CODE VARCHAR(2048),
    CONSUMER_KEY_ID INTEGER,
    CALLBACK_URL VARCHAR(2048),
    SCOPE VARCHAR(2048),
    AUTHZ_USER VARCHAR (100),
    TENANT_ID INTEGER,
    USER_DOMAIN VARCHAR(50),
    TIME_CREATED DATETIME,
    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,
    PRIMARY KEY (CODE_ID),
    FOREIGN KEY (CONSUMER_KEY_ID) REFERENCES IDN_OAUTH_CONSUMER_APPS(ID)
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[IDN_OAUTH2_ACCESS_TOKEN_SCOPE]') AND TYPE IN (N'U'))
  CREATE TABLE IDN_OAUTH2_ACCESS_TOKEN_SCOPE (
    TOKEN_ID VARCHAR (255),
    TOKEN_SCOPE VARCHAR (100),
    TENANT_ID INTEGER DEFAULT -1,
    PRIMARY KEY (TOKEN_ID, TOKEN_SCOPE),
    FOREIGN KEY (TOKEN_ID) REFERENCES IDN_OAUTH2_ACCESS_TOKEN(TOKEN_ID)
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[IDN_OAUTH2_SCOPE_BINDING]') AND TYPE IN (N'U'))
  CREATE TABLE IDN_OAUTH2_SCOPE_BINDING (
    SCOPE_ID INTEGER NOT NULL,
    SCOPE_BINDING VARCHAR(255),
    FOREIGN KEY (SCOPE_ID) REFERENCES IDN_OAUTH2_SCOPE(SCOPE_ID) 
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[IDN_OAUTH2_RESOURCE_SCOPE]') AND TYPE IN (N'U'))
  CREATE TABLE 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) 
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[IDN_OPENID_REMEMBER_ME]') AND TYPE IN (N'U'))
  CREATE TABLE IDN_OPENID_REMEMBER_ME (
    USER_NAME VARCHAR(255) NOT NULL,
    TENANT_ID INTEGER DEFAULT 0,
    COOKIE_VALUE VARCHAR(1024),
    CREATED_TIME DATETIME,
    PRIMARY KEY (USER_NAME, TENANT_ID)
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[IDN_OPENID_USER_RPS]') AND TYPE IN (N'U'))
  CREATE TABLE 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)
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[IDN_OPENID_ASSOCIATIONS]') AND TYPE IN (N'U'))
  CREATE TABLE IDN_OPENID_ASSOCIATIONS (
    HANDLE VARCHAR(255) NOT NULL,
    ASSOC_TYPE VARCHAR(255) NOT NULL,
    EXPIRE_IN DATETIME NOT NULL,
    MAC_KEY VARCHAR(255) NOT NULL,
    ASSOC_STORE VARCHAR(128) DEFAULT 'SHARED',
    TENANT_ID INTEGER DEFAULT -1,
    PRIMARY KEY (HANDLE)
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[IDN_IDENTITY_USER_DATA]') AND TYPE IN (N'U'))
  CREATE TABLE 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)
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[IDN_IDENTITY_META_DATA]') AND TYPE IN (N'U'))
  CREATE TABLE 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)
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[IDN_THRIFT_SESSION]') AND TYPE IN (N'U'))
  CREATE TABLE 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)
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[IDN_AUTH_SESSION_STORE]') AND TYPE IN (N'U'))
  CREATE TABLE IDN_AUTH_SESSION_STORE (
    SESSION_ID VARCHAR (100) NOT NULL,
    SESSION_TYPE VARCHAR(100) NOT NULL,
    OPERATION VARCHAR(10) NOT NULL,
    SESSION_OBJECT VARBINARY(MAX),
    TIME_CREATED BIGINT,
    TENANT_ID INTEGER DEFAULT -1,
    EXPIRY_TIME BIGINT,
    PRIMARY KEY (SESSION_ID, SESSION_TYPE, TIME_CREATED, OPERATION)
  );
  
  IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[IDN_AUTH_SESSION_APP_INFO]') AND TYPE IN (N'U'))
  CREATE TABLE 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)
  );
  
  IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[IDN_AUTH_SESSION_META_DATA]') AND TYPE IN (N'U'))
  CREATE TABLE 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)
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[IDN_AUTH_TEMP_SESSION_STORE]') AND TYPE IN (N'U'))
  CREATE TABLE IDN_AUTH_TEMP_SESSION_STORE (
    SESSION_ID VARCHAR (100) NOT NULL,
    SESSION_TYPE VARCHAR(100) NOT NULL,
    OPERATION VARCHAR(10) NOT NULL,
    SESSION_OBJECT VARBINARY(MAX),
    TIME_CREATED BIGINT,
    TENANT_ID INTEGER DEFAULT -1,
    EXPIRY_TIME BIGINT,
    PRIMARY KEY (SESSION_ID, SESSION_TYPE, TIME_CREATED, OPERATION)
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[IDN_AUTH_USER]') AND TYPE IN (N'U'))
  CREATE TABLE 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));
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[IDN_AUTH_USER_SESSION_MAPPING]') AND TYPE IN (N'U'))
  CREATE TABLE IDN_AUTH_USER_SESSION_MAPPING (
  	USER_ID VARCHAR(255) NOT NULL,
  	SESSION_ID VARCHAR(255) NOT NULL,
  	CONSTRAINT USER_SESSION_STORE_CONSTRAINT UNIQUE (USER_ID, SESSION_ID));
  
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[SP_FEDERATED_IDP]') AND TYPE IN (N'U'))
  CREATE TABLE SP_FEDERATED_IDP (
    ID INTEGER NOT NULL,
    TENANT_ID INTEGER NOT NULL,
    AUTHENTICATOR_ID INTEGER NOT NULL,
    PRIMARY KEY (ID, AUTHENTICATOR_ID),
    CONSTRAINT STEP_ID_CONSTRAINT FOREIGN KEY (ID) REFERENCES SP_AUTH_STEP (ID) 
  );
  
  IF NOT EXISTS(SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[SP_AUTH_SCRIPT]') AND TYPE IN (N'U'))
  CREATE TABLE IDN_ARTIFACT_STORE (
    ID         VARCHAR(255)           NOT NULL,
    TENANT_ID  INTEGER                NOT NULL,
    ARTIFACT   VARBINARY(MAX)         DEFAULT NULL,
    IDENTIFIER  VARCHAR(255)           NOT NULL,
    ARTIFACT_TYPE       VARCHAR(255)   NOT NULL,
    CONTENT_TYPE        VARCHAR(255)   DEFAULT NULL,
    PRIMARY KEY (ID),
    UNIQUE (IDENTIFIER , ARTIFACT_TYPE)
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[IDN_USER_ACCOUNT_ASSOCIATION]') AND TYPE IN (N'U'))
  CREATE TABLE 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)
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[FIDO_DEVICE_STORE]') AND TYPE IN (N'U'))
  CREATE TABLE FIDO_DEVICE_STORE (
    TENANT_ID INTEGER,
    DOMAIN_NAME VARCHAR(255) NOT NULL,
    USER_NAME VARCHAR(45) NOT NULL,
    TIME_REGISTERED DATETIME,
    KEY_HANDLE VARCHAR(200) NOT NULL,
    DEVICE_DATA VARCHAR(2048) NOT NULL,
    PRIMARY KEY (TENANT_ID, DOMAIN_NAME, USER_NAME, KEY_HANDLE)
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[FIDO2_DEVICE_STORE]') AND TYPE IN (N'U'))
  CREATE TABLE FIDO2_DEVICE_STORE (
    TENANT_ID INTEGER,
    DOMAIN_NAME VARCHAR(255) NOT NULL,
    USER_NAME VARCHAR(45) NOT NULL,
    TIME_REGISTERED DATETIME,
    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,
    PRIMARY KEY (CREDENTIAL_ID, USER_HANDLE)
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[WF_REQUEST]') AND TYPE IN (N'U'))
  CREATE TABLE WF_REQUEST (
    UUID VARCHAR (45),
    CREATED_BY VARCHAR (255),
    TENANT_ID INTEGER DEFAULT -1,
    OPERATION_TYPE VARCHAR (50),
    CREATED_AT DATETIME,
    UPDATED_AT DATETIME,
    STATUS VARCHAR (30),
    REQUEST VARBINARY(MAX),
    PRIMARY KEY (UUID)
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[WF_BPS_PROFILE]') AND TYPE IN (N'U'))
  CREATE TABLE WF_BPS_PROFILE (
    PROFILE_NAME VARCHAR(45),
    HOST_URL_MANAGER VARCHAR(255),
    HOST_URL_WORKER VARCHAR(255),
    USERNAME VARCHAR(45),
    PASSWORD VARCHAR(1023),
    CALLBACK_HOST VARCHAR (45),
    TENANT_ID INTEGER DEFAULT -1,
    PRIMARY KEY (PROFILE_NAME, TENANT_ID)
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[WF_WORKFLOW]') AND TYPE IN (N'U'))
  CREATE TABLE 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)
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[WF_WORKFLOW_CONFIG_PARAM]') AND TYPE IN (N'U'))
  CREATE TABLE 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)
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[WF_REQUEST_ENTITY_RELATIONSHIP]') AND TYPE IN (N'U'))
  CREATE TABLE 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)
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[WF_WORKFLOW_REQUEST_RELATION]') AND TYPE IN (N'U'))
  CREATE TABLE WF_WORKFLOW_REQUEST_RELATION(
    RELATIONSHIP_ID VARCHAR (45),
    WORKFLOW_ID VARCHAR (45),
    REQUEST_ID VARCHAR (45),
    UPDATED_AT DATETIME,
    STATUS VARCHAR (30),
    TENANT_ID INTEGER DEFAULT -1,
    PRIMARY KEY (RELATIONSHIP_ID),
    FOREIGN KEY (WORKFLOW_ID) REFERENCES WF_WORKFLOW(ID),
    FOREIGN KEY (REQUEST_ID) REFERENCES WF_REQUEST(UUID)
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[IDN_RECOVERY_DATA]') AND TYPE IN (N'U'))
  CREATE TABLE 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 DATETIME NOT NULL,
    REMAINING_SETS VARCHAR(2500) DEFAULT NULL,
    PRIMARY KEY(USER_NAME, USER_DOMAIN, TENANT_ID, SCENARIO,STEP),
    UNIQUE(CODE)
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[IDN_OIDC_JTI]') AND TYPE IN (N'U'))
  CREATE TABLE IDN_OIDC_JTI  (
    JWT_ID VARCHAR(255) NOT NULL,
    EXP_TIME DATETIME NOT NULL,
    TIME_CREATED DATETIME NOT NULL,
    PRIMARY KEY (JWT_ID)
  );
  
  IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[IDN_FUNCTION_LIBRARY]') AND TYPE IN (N'U'))
  CREATE TABLE IDN_FUNCTION_LIBRARY (
  	NAME VARCHAR(255) NOT NULL,
  	DESCRIPTION VARCHAR(1023),
  	TYPE VARCHAR(255) NOT NULL,
  	TENANT_ID INTEGER NOT NULL,
  	DATA VARBINARY(MAX) NOT NULL,
  	PRIMARY KEY (TENANT_ID,NAME)
  );
  
  -- --------------------------- 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_CK_AU ON IDN_OAUTH2_ACCESS_TOKEN(CONSUMER_KEY_ID, AUTHZ_USER, TOKEN_STATE, USER_TYPE);
  CREATE INDEX IDX_AT_TI_UD ON IDN_OAUTH2_ACCESS_TOKEN(AUTHZ_USER, TENANT_ID, TOKEN_STATE, USER_DOMAIN);
  CREATE INDEX IDX_AT_AU_TID_UD_TS_CKID ON IDN_OAUTH2_ACCESS_TOKEN(AUTHZ_USER, TENANT_ID, USER_DOMAIN, TOKEN_STATE, CONSUMER_KEY_ID);
  CREATE INDEX IDX_AT_AU_CKID_TS_UT ON IDN_OAUTH2_ACCESS_TOKEN(AUTHZ_USER, CONSUMER_KEY_ID, TOKEN_STATE, USER_TYPE);
  CREATE INDEX IDX_AT_RTH ON IDN_OAUTH2_ACCESS_TOKEN(REFRESH_TOKEN_HASH);
  
  -- 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);
  
  -- 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);
  CREATE INDEX IDX_SC_N_TID ON IDN_OAUTH2_SCOPE(NAME, 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_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_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_TID_CK ON IDN_OIDC_PROPERTY(TENANT_ID,CONSUMER_KEY);
  
  -- IDN_FIDO2_PROPERTY --
  CREATE INDEX IDX_FIDO2_STR ON FIDO2_DEVICE_STORE(USER_NAME, TENANT_ID, DOMAIN_NAME, CREDENTIAL_ID, USER_HANDLE);
  
  
  -- End of IDENTITY Tables--
  
  
  -- Start of CONSENT-MGT Tables --
  
  IF NOT EXISTS ( SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[CM_RECEIPT]') AND TYPE IN (N'U'))
  CREATE TABLE CM_RECEIPT (
    CONSENT_RECEIPT_ID  VARCHAR(255) NOT NULL,
    VERSION             VARCHAR(255) NOT NULL,
    JURISDICTION        VARCHAR(255) NOT NULL,
    CONSENT_TIMESTAMP   DATETIME    NOT NULL,
    COLLECTION_METHOD   VARCHAR(255) NOT NULL,
    LANGUAGE            VARCHAR(255) NOT NULL,
    PII_PRINCIPAL_ID    VARCHAR(255) NOT NULL,
    PRINCIPAL_TENANT_ID INTEGER DEFAULT '-1234',
    POLICY_URL          VARCHAR(255) NOT NULL,
    STATE               VARCHAR(255) NOT NULL,
    PII_CONTROLLER      VARCHAR(2048) NOT NULL,
    PRIMARY KEY (CONSENT_RECEIPT_ID)
  );
  
  IF NOT EXISTS ( SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[CM_SP_PURPOSE_PURPOSE_CAT_ASSC]') AND TYPE IN (N'U'))
  CREATE TABLE CM_SP_PURPOSE_PURPOSE_CAT_ASSC (
    SP_PURPOSE_ASSOC_ID INTEGER NOT NULL,
    PURPOSE_CATEGORY_ID INTEGER NOT NULL,
    CONSTRAINT CM_SP_PURPOSE_PURPOSE_CAT_ASSC_CNT UNIQUE (SP_PURPOSE_ASSOC_ID, PURPOSE_CATEGORY_ID),
    FOREIGN KEY (SP_PURPOSE_ASSOC_ID) REFERENCES CM_SP_PURPOSE_ASSOC (ID),
    FOREIGN KEY (PURPOSE_CATEGORY_ID) REFERENCES CM_PURPOSE_CATEGORY (ID)
  );
  
  IF NOT EXISTS ( SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[CM_PURPOSE_PII_CAT_ASSOC]') AND TYPE IN (N'U'))
  CREATE TABLE CM_PURPOSE_PII_CAT_ASSOC (
    PURPOSE_ID         INTEGER NOT NULL,
    CM_PII_CATEGORY_ID INTEGER NOT NULL,
    IS_MANDATORY       INTEGER NOT NULL,
    CONSTRAINT CM_PURPOSE_PII_CAT_ASSOC_CNT UNIQUE (PURPOSE_ID, CM_PII_CATEGORY_ID)
  );
  
  IF NOT EXISTS ( SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[CM_SP_PURPOSE_PII_CAT_ASSOC]') AND TYPE IN (N'U'))
  CREATE TABLE CM_SP_PURPOSE_PII_CAT_ASSOC (
    SP_PURPOSE_ASSOC_ID INTEGER NOT NULL,
    PII_CATEGORY_ID     INTEGER NOT NULL,
    VALIDITY            VARCHAR(1023),
    CONSTRAINT CM_SP_PURPOSE_PII_CAT_ASSOC_CNT UNIQUE (SP_PURPOSE_ASSOC_ID, PII_CATEGORY_ID),
    FOREIGN KEY (PII_CATEGORY_ID) REFERENCES CM_PII_CATEGORY (ID),
    FOREIGN KEY (SP_PURPOSE_ASSOC_ID) REFERENCES CM_SP_PURPOSE_ASSOC (ID)
  );
  
  IF NOT EXISTS ( SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[CM_CONSENT_RECEIPT_PROPERTY]') AND TYPE IN (N'U'))
  CREATE TABLE CM_CONSENT_RECEIPT_PROPERTY (
    CONSENT_RECEIPT_ID VARCHAR(255)  NOT NULL,
    NAME               VARCHAR(255)  NOT NULL,
    VALUE              VARCHAR(1023) NOT NULL,
    CONSTRAINT CM_CONSENT_RECEIPT_PROPERTY_CNT UNIQUE (CONSENT_RECEIPT_ID, NAME),
    FOREIGN KEY (CONSENT_RECEIPT_ID) REFERENCES CM_RECEIPT (CONSENT_RECEIPT_ID)
  );
  
  -- INSERT INTO CM_PURPOSE (NAME, DESCRIPTION, PURPOSE_GROUP, GROUP_TYPE, TENANT_ID) VALUES ('DEFAULT', 'For core functionalities of the product', 'DEFAULT', 'SP', '-1234');
  
  -- INSERT INTO CM_PURPOSE_CATEGORY (NAME, DESCRIPTION, TENANT_ID) VALUES ('DEFAULT','For core functionalities of the product', '-1234');
  
  -- End of CONSENT-MGT Tables --
  
  -- Start of API-MGT Tables--
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AM_MONETIZATION_USAGE]') AND TYPE IN (N'U'))
  CREATE TABLE AM_MONETIZATION_USAGE (
  	ID VARCHAR(100) NOT NULL,
  	STATE VARCHAR(50) NOT NULL,
  	STATUS VARCHAR(50) NOT NULL,
  	STARTED_TIME VARCHAR(50) NOT NULL,
  	PUBLISHED_TIME VARCHAR(50) NOT NULL,
  	PRIMARY KEY(ID)
  );
  
  
  
  -- TODO: Have to add ON UPDATE CASCADE for the FOREIGN KEY(APPLICATION_ID) and FOREIGN KEY(API_ID) relations
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AM_APPLICATION_KEY_MAPPING]') AND TYPE IN (N'U'))
  CREATE TABLE AM_APPLICATION_KEY_MAPPING (
      UUID VARCHAR(512),
      APPLICATION_ID INTEGER,
      CONSUMER_KEY VARCHAR(512),
      KEY_TYPE VARCHAR(512) NOT NULL,
      STATE VARCHAR(30) NOT NULL,
      CREATE_MODE VARCHAR(30) DEFAULT 'CREATED',
      KEY_MANAGER VARCHAR(512),
      FOREIGN KEY(APPLICATION_ID) REFERENCES AM_APPLICATION(APPLICATION_ID),
      PRIMARY KEY(APPLICATION_ID,KEY_TYPE,KEY_MANAGER)
  );
  
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AM_APP_KEY_DOMAIN_MAPPING]') AND TYPE IN (N'U'))
  CREATE TABLE AM_APP_KEY_DOMAIN_MAPPING (
     CONSUMER_KEY VARCHAR(512),
     AUTHZ_DOMAIN VARCHAR(255) DEFAULT 'ALL',
     PRIMARY KEY (CONSUMER_KEY,AUTHZ_DOMAIN)
  
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AM_API_COMMENTS]') AND TYPE IN (N'U'))
  CREATE TABLE AM_API_COMMENTS (
      COMMENT_ID VARCHAR(255) NOT NULL,
      COMMENT_TEXT VARCHAR(512),
      COMMENTED_USER VARCHAR(255),
      DATE_COMMENTED DATETIME NOT NULL,
      API_ID INTEGER,
      FOREIGN KEY(API_ID) REFERENCES AM_API(API_ID),
      PRIMARY KEY (COMMENT_ID)
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AM_API_RATINGS]') AND TYPE IN (N'U'))
  CREATE TABLE AM_API_RATINGS (
      RATING_ID VARCHAR(255) NOT NULL,
      API_ID INTEGER,
      RATING INTEGER,
      SUBSCRIBER_ID INTEGER,
      FOREIGN KEY(API_ID) REFERENCES AM_API(API_ID) ON UPDATE CASCADE,
      FOREIGN KEY(SUBSCRIBER_ID) REFERENCES AM_SUBSCRIBER(SUBSCRIBER_ID) ON UPDATE CASCADE,
      PRIMARY KEY (RATING_ID)
  );
  
  -- Start of IDP-APPLICATION-MGT Tables --
  
  -- End of IDP-APPLICATION-MGT Tables --
  
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AM_API_SCOPES]') AND TYPE IN (N'U'))
  CREATE TABLE AM_API_SCOPES (
     API_ID  INTEGER NOT NULL,
     SCOPE_ID  INTEGER NOT NULL,
     FOREIGN KEY (API_ID) REFERENCES AM_API (API_ID),
     FOREIGN KEY (SCOPE_ID) REFERENCES IDN_OAUTH2_SCOPE (SCOPE_ID),
     PRIMARY KEY (API_ID, SCOPE_ID)
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AM_API_DEFAULT_VERSION]') AND TYPE IN (N'U'))
  CREATE TABLE AM_API_DEFAULT_VERSION (
              DEFAULT_VERSION_ID INTEGER NOT NULL IDENTITY(1,1),
              API_NAME VARCHAR(256) NOT NULL ,
              API_PROVIDER VARCHAR(256) NOT NULL ,
              DEFAULT_API_VERSION VARCHAR(30) ,
              PUBLISHED_DEFAULT_API_VERSION VARCHAR(30) ,
              PRIMARY KEY (DEFAULT_VERSION_ID)
  );
  
  CREATE INDEX IDX_SUB_APP_ID ON AM_SUBSCRIPTION (APPLICATION_ID, SUBSCRIPTION_ID);
  
  
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AM_ALERT_TYPES_VALUES]') AND TYPE IN (N'U'))
  CREATE TABLE  AM_ALERT_TYPES_VALUES (
                ALERT_TYPE_ID INTEGER,
                USER_NAME VARCHAR(255) NOT NULL ,
  	      STAKE_HOLDER VARCHAR(100) NOT NULL ,
  	      CONSTRAINT AM_ALERT_TYPES_VALUES_CONST UNIQUE (ALERT_TYPE_ID,USER_NAME,STAKE_HOLDER)
  );
  
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AM_ALERT_EMAILLIST_DETAILS]') AND TYPE IN (N'U'))
  CREATE TABLE  AM_ALERT_EMAILLIST_DETAILS (
                EMAIL_LIST_ID INTEGER,
  	      EMAIL VARCHAR(255),
  	      CONSTRAINT AM_ALERT_EMAILLIST_DETAILS_CONST UNIQUE (EMAIL_LIST_ID,EMAIL)
  );
  
  -- AM Throttling tables --
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AM_CERTIFICATE_METADATA]') AND TYPE IN (N'U'))
  CREATE TABLE AM_CERTIFICATE_METADATA (
    TENANT_ID INTEGER NOT NULL,
    ALIAS VARCHAR(45) NOT NULL,
    END_POINT VARCHAR(100) NOT NULL,
    CONSTRAINT PK_ALIAS PRIMARY KEY (ALIAS)
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AM_API_CLIENT_CERTIFICATE]') AND TYPE IN (N'U'))
  CREATE TABLE AM_API_CLIENT_CERTIFICATE (
      TENANT_ID INTEGER NOT NULL,
      ALIAS VARCHAR(45) NOT NULL,
      API_ID INTEGER NOT NULL,
      CERTIFICATE VARBINARY(MAX) NOT NULL,
      REMOVED BIT NOT NULL DEFAULT 0,
      TIER_NAME VARCHAR(512),
      PRIMARY KEY (ALIAS, TENANT_ID, REMOVED),
      FOREIGN KEY (API_ID) REFERENCES AM_API(API_ID)
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AM_APPLICATION_GROUP_MAPPING]') AND TYPE IN (N'U'))
  CREATE TABLE AM_APPLICATION_GROUP_MAPPING (
      APPLICATION_ID INTEGER NOT NULL,
      GROUP_ID VARCHAR(512),
      TENANT VARCHAR(255),
      PRIMARY KEY (APPLICATION_ID,GROUP_ID,TENANT),
      FOREIGN KEY (APPLICATION_ID) REFERENCES AM_APPLICATION(APPLICATION_ID) 
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AM_USAGE_UPLOADED_FILES]') AND TYPE IN (N'U'))
  CREATE TABLE AM_USAGE_UPLOADED_FILES (
    TENANT_DOMAIN VARCHAR(255) NOT NULL,
    FILE_NAME VARCHAR(255) NOT NULL,
    FILE_TIMESTAMP DATETIME DEFAULT GETDATE(),
    FILE_PROCESSED INTEGER DEFAULT 0,
    FILE_CONTENT VARBINARY(MAX) DEFAULT NULL,
    PRIMARY KEY (TENANT_DOMAIN, FILE_NAME, FILE_TIMESTAMP)
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AM_APPLICATION_ATTRIBUTES]') AND TYPE IN (N'U'))
  CREATE TABLE AM_APPLICATION_ATTRIBUTES (
    APPLICATION_ID INTEGER NOT NULL,
    NAME VARCHAR(255) NOT NULL,
    APP_ATTRIBUTE VARCHAR(1024) NOT NULL,
    TENANT_ID INTEGER NOT NULL,
    PRIMARY KEY (APPLICATION_ID,NAME),
    FOREIGN KEY (APPLICATION_ID) REFERENCES AM_APPLICATION (APPLICATION_ID) 
  ) ;
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AM_LABELS]') AND TYPE IN (N'U'))
  CREATE TABLE AM_LABELS (
    LABEL_ID VARCHAR(50),
    NAME VARCHAR(255),
    DESCRIPTION VARCHAR(1024),
    TENANT_DOMAIN VARCHAR(255),
    UNIQUE (NAME,TENANT_DOMAIN),
    PRIMARY KEY (LABEL_ID)
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AM_LABEL_URLS]') AND TYPE IN (N'U'))
  CREATE TABLE AM_LABEL_URLS (
    LABEL_ID VARCHAR(50),
    ACCESS_URL VARCHAR(255),
    PRIMARY KEY (LABEL_ID,ACCESS_URL),
    FOREIGN KEY (LABEL_ID) REFERENCES AM_LABELS(LABEL_ID)
  );
  
  
  -- BotDATA Email table--
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AM_NOTIFICATION_SUBSCRIBER]') AND TYPE IN (N'U'))
  CREATE TABLE AM_NOTIFICATION_SUBSCRIBER (
      UUID VARCHAR(255),
      CATEGORY VARCHAR(255),
      NOTIFICATION_METHOD VARCHAR(255),
      SUBSCRIBER_ADDRESS VARCHAR(255) NOT NULL,
      PRIMARY KEY(UUID, SUBSCRIBER_ADDRESS)
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AM_REVOKED_JWT]') AND TYPE IN (N'U'))
  CREATE TABLE AM_REVOKED_JWT (
      UUID VARCHAR(255) NOT NULL,
      SIGNATURE VARCHAR(2048) NOT NULL,
      EXPIRY_TIMESTAMP BIGINT NOT NULL,
      TENANT_ID INTEGER DEFAULT -1,
      TOKEN_TYPE VARCHAR(15) DEFAULT 'DEFAULT',
      TIME_CREATED DATETIME DEFAULT GETDATE(),
      PRIMARY KEY (UUID)
  );
  
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AM_KEY_MANAGER]') AND TYPE IN (N'U'))
  CREATE TABLE AM_KEY_MANAGER (
    UUID VARCHAR(50) NOT NULL,
    NAME VARCHAR(100) NULL,
    DISPLAY_NAME VARCHAR(100) NULL,
    DESCRIPTION VARCHAR(256) NULL,
    TYPE VARCHAR(45) NULL,
    CONFIGURATION VARBINARY(MAX) NULL,
    ENABLED BIT DEFAULT 1,
    TENANT_DOMAIN VARCHAR(100) NULL,
    PRIMARY KEY (UUID),
    UNIQUE (NAME,TENANT_DOMAIN)
    );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AM_GW_API_ARTIFACTS]') AND TYPE IN (N'U'))
  CREATE TABLE  AM_GW_API_ARTIFACTS (
    API_ID varchar(255) NOT NULL,
    REVISION_ID varchar(255) NOT NULL,
    ARTIFACT VARBINARY(MAX),
    TIME_STAMP DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    PRIMARY KEY (REVISION_ID, API_ID),
    FOREIGN KEY (API_ID) REFERENCES AM_GW_PUBLISHED_API_DETAILS(API_ID) ON UPDATE CASCADE ON DELETE NO ACTION
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AM_GW_API_DEPLOYMENTS]') AND TYPE IN (N'U'))
  CREATE TABLE AM_GW_API_DEPLOYMENTS (
    API_ID VARCHAR(255) NOT NULL,
    REVISION_ID VARCHAR(255) NOT NULL,
    LABEL VARCHAR(255) NOT NULL,
    PRIMARY KEY (REVISION_ID, API_ID,LABEL),
    FOREIGN KEY (API_ID) REFERENCES AM_GW_PUBLISHED_API_DETAILS(API_ID) ON UPDATE CASCADE ON DELETE NO ACTION
  ) ;
  GO
  -- End of API-MGT Tables --
  
  -- Timestamp Trigger for Artifact synchronizer --
  
  CREATE TRIGGER dbo.TIMESTAMP ON dbo.AM_GW_API_ARTIFACTS
    AFTER INSERT, UPDATE
      AS
      UPDATE f set TIMESTAMP=GETDATE()
      FROM
      dbo.[AM_GW_API_ARTIFACTSFG] AS f
      INNER JOIN inserted
      AS i
      ON f.TIMESTAMP = i.TIMESTAMP;
  GO
  
  -- Start of Cascade triggers --
  
  CREATE OR ALTER TRIGGER TRG_DEL_IDN_CON_APPS on IDN_OAUTH_CONSUMER_APPS
    INSTEAD OF DELETE
       AS 
        BEGIN
          DELETE IOSV FROM DELETED, IDN_OAUTH2_SCOPE_VALIDATORS IOSV WHERE IOSV.APP_ID = DELETED.ID
          DELETE IOP FROM DELETED, IDN_OIDC_PROPERTY IOP WHERE IOP.CONSUMER_KEY = DELETED.CONSUMER_KEY
          DELETE IOROR FROM DELETED,IDN_OIDC_REQ_OBJECT_REFERENCE IOROR WHERE IOROR.CONSUMER_KEY_ID = DELETED.ID
          DELETE IO2AC FROM IDELETED,DN_OAUTH2_AUTHORIZATION_CODE IO2AC WHERE IO2AC.CONSUMER_KEY_ID = DELETED.ID
          DELETE IO2AT FROM DELETED,IDN_OAUTH2_ACCESS_TOKEN IO2AT WHERE IO2AT.CONSUMER_KEY_ID = DELETED.ID
          DELETE IOAT FROM DELETED,IDN_OAUTH1A_ACCESS_TOKEN IOAT WHERE IOAT.CONSUMER_KEY_ID = DELETED.ID
          DELETE IORT FROM DELETED,IDN_OAUTH1A_REQUEST_TOKEN IORT WHERE IORT.CONSUMER_KEY_ID = DELETED.ID
        END
        DELETE FROM IDN_OAUTH_CONSUMER_APPS WHERE ((ID) IN (SELECT ID FROM DELETED)) AND ((CONSUMER_KEY) IN (SELECT CONSUMER_KEY FROM DELETED));
  ;
  GO
  
  CREATE OR ALTER TRIGGER TRG_AM_GW_PUBLISHED_API_DETAILS on AM_GW_PUBLISHED_API_DETAILS
    INSTEAD OF DELETE
       AS
        BEGIN
          DELETE AGA FROM DELETED, AM_GW_API_ARTIFACTS  AGA WHERE AGA.API_ID = DELETED.API_ID
        END
        DELETE FROM AM_GW_PUBLISHED_API_DETAILS WHERE (API_ID) IN (SELECT API_ID FROM DELETED);
  ;
  GO
  
  CREATE OR ALTER TRIGGER TRG_DEL_IDN_OA2_ACC on IDN_OAUTH2_ACCESS_TOKEN
    INSTEAD OF DELETE
       AS 
        BEGIN
          DELETE IO2ATS FROM DELETED, IDN_OAUTH2_ACCESS_TOKEN_SCOPE IO2ATS WHERE IO2ATS.TOKEN_ID = DELETED.TOKEN_ID
          DELETE IOROR FROM DELETED, IDN_OIDC_REQ_OBJECT_REFERENCE IOROR WHERE IOROR.TOKEN_ID = DELETED.TOKEN_ID
        END
        DELETE FROM IDN_OAUTH2_ACCESS_TOKEN WHERE (TOKEN_ID) IN (SELECT TOKEN_ID FROM DELETED);
  ;  
  GO
  
  CREATE OR ALTER TRIGGER TRG_DEL_IDN_OAUTH2_SCOPE on IDN_OAUTH2_SCOPE
    INSTEAD OF DELETE
       AS 
        BEGIN
          DELETE IOSB FROM DELETED, IDN_OAUTH2_SCOPE_BINDING IOSB WHERE IOSB.SCOPE_ID = DELETED.SCOPE_ID
          DELETE IORS FROM DELETED, IDN_OAUTH2_RESOURCE_SCOPE IORS WHERE IORS.SCOPE_ID = DELETED.SCOPE_ID
          DELETE AMS FROM DELETED, AM_API_SCOPES AMS WHERE AMS.SCOPE_ID = DELETED.SCOPE_ID
        END
        DELETE FROM IDN_OAUTH2_SCOPE WHERE (SCOPE_ID) IN (SELECT SCOPE_ID FROM DELETED);
  ;
  GO
  
  CREATE OR ALTER TRIGGER TRG_DEL_SP_APP on SP_APP
    INSTEAD OF DELETE
       AS 
        BEGIN
          DELETE SAS FROM DELETED, SP_AUTH_STEP SAS WHERE SAS.APP_ID = DELETED.ID
          DELETE SRPA FROM DELETED,SP_REQ_PATH_AUTHENTICATOR SRPA WHERE SRPA.APP_ID = DELETED.ID
          DELETE SPC FROM DELETED,SP_PROVISIONING_CONNECTOR SPC WHERE SPC.APP_ID = DELETED.ID
          DELETE META FROM DELETED,SP_METADATA META WHERE META.SP_ID = DELETED.ID
          DELETE SIA FROM DELETED,SP_INBOUND_AUTH SIA WHERE SIA.APP_ID = DELETED.ID
          DELETE SCM FROM DELETED,SP_CLAIM_MAPPING SCM WHERE SCM.APP_ID = DELETED.ID
          DELETE SRM FROM DELETED,SP_ROLE_MAPPING SRM WHERE SRM.APP_ID = DELETED.ID
          DELETE SCD FROM DELETED,SP_CLAIM_DIALECT SCD WHERE SCD.APP_ID = DELETED.ID
        END
        DELETE FROM SP_APP WHERE (ID) IN (SELECT ID FROM DELETED);
  ;
  GO
  
  CREATE OR ALTER TRIGGER TRG_DEL_SP_AUTH_STEP on SP_AUTH_STEP
    INSTEAD OF DELETE
       AS 
        BEGIN
          DELETE AFI FROM DELETED, SP_FEDERATED_IDP AFI WHERE AFI.ID = DELETED.ID
        END
        DELETE FROM SP_AUTH_STEP WHERE (ID) IN (SELECT ID FROM DELETED);
  ;
  GO
  
  CREATE OR ALTER TRIGGER TRG_DEL_IDP on IDP
    INSTEAD OF DELETE
       AS
        BEGIN
          DELETE IR FROM DELETED, IDP_ROLE IR WHERE IR.IDP_ID = DELETED.ID
          DELETE IC FROM DELETED, IDP_CLAIM IC WHERE IC.IDP_ID = DELETED.ID
          DELETE IA FROM DELETED, IDP_AUTHENTICATOR IA WHERE IA.IDP_ID = DELETED.ID
          DELETE IM FROM DELETED, IDP_METADATA IM WHERE IM.IDP_ID = DELETED.ID
          DELETE IPC FROM DELETED, IDP_PROVISIONING_CONFIG IPC WHERE IPC.IDP_ID = DELETED.ID
          DELETE ILC FROM DELETED, IDP_LOCAL_CLAIM ILC WHERE ILC.IDP_ID = DELETED.ID
          DELETE IAI FROM DELETED, IDN_ASSOCIATED_ID IAI WHERE IAI.IDP_ID = DELETED.ID
        END
        DELETE FROM IDP WHERE (ID) IN (SELECT ID FROM DELETED);
  ; 
  GO
  
  CREATE OR ALTER TRIGGER TRG_DEL_IDP_ROLE on IDP_ROLE
    INSTEAD OF DELETE
       AS 
        BEGIN
          DELETE IRM FROM DELETED, IDP_ROLE_MAPPING IRM WHERE IRM.IDP_ROLE_ID = DELETED.ID
        END
        DELETE FROM IDP_ROLE WHERE (ID) IN (SELECT ID FROM DELETED);
  ;
  GO
  
  CREATE OR ALTER TRIGGER TRG_DEL_IDP_CLAIM on IDP_CLAIM
    INSTEAD OF DELETE
       AS 
        BEGIN
          DELETE ICM FROM DELETED, IDP_CLAIM_MAPPING ICM WHERE ICM.IDP_CLAIM_ID = DELETED.ID
        END
        DELETE FROM IDP_CLAIM WHERE (ID) IN (SELECT ID FROM DELETED);
  ;
  GO
  
  CREATE OR ALTER TRIGGER TRG_DEL_IDP_AUTHENTICATOR on IDP_AUTHENTICATOR
    INSTEAD OF DELETE
       AS 
        BEGIN
          DELETE IAP FROM DELETED, IDP_AUTHENTICATOR_PROPERTY IAP WHERE IAP.AUTHENTICATOR_ID = DELETED.ID
        END
        DELETE FROM IDP_AUTHENTICATOR WHERE (ID) IN (SELECT ID FROM DELETED);
  ;
  GO
  
  CREATE OR ALTER TRIGGER TRG_DEL_IDP_PRO_CONFIG on IDP_PROVISIONING_CONFIG
    INSTEAD OF DELETE
       AS 
        BEGIN
          DELETE IPCP FROM DELETED, IDP_PROV_CONFIG_PROPERTY IPCP WHERE IPCP.PROVISIONING_CONFIG_ID = DELETED.ID
          DELETE IPE FROM DELETED, IDP_PROVISIONING_ENTITY IPE WHERE IPE.PROVISIONING_CONFIG_ID = DELETED.ID
        END
        DELETE FROM IDP_PROVISIONING_CONFIG WHERE (ID) IN (SELECT ID FROM DELETED);
  ;
  GO
  
  CREATE OR ALTER TRIGGER TRG_DEL_WF_WORKFLOW on WF_WORKFLOW
    INSTEAD OF DELETE
       AS 
        BEGIN
          DELETE WWA FROM DELETED, WF_WORKFLOW_ASSOCIATION WWA WHERE WWA.WORKFLOW_ID = DELETED.ID
          DELETE WWCP FROM DELETED, WF_WORKFLOW_CONFIG_PARAM WWCP WHERE WWCP.WORKFLOW_ID = DELETED.ID
          DELETE WWRR FROM DELETED, WF_WORKFLOW_REQUEST_RELATION WWRR WHERE WWRR.WORKFLOW_ID = DELETED.ID
        END
        DELETE FROM WF_WORKFLOW WHERE (ID) IN (SELECT ID FROM DELETED);
  ;
  GO
  
  CREATE OR ALTER TRIGGER TRG_DEL_IDN_CLAIM_DIALECT on IDN_CLAIM_DIALECT
    INSTEAD OF DELETE
       AS 
        BEGIN
          DELETE ICL FROM DELETED, IDN_CLAIM ICL WHERE ICL.DIALECT_ID = DELETED.ID
        END
        DELETE FROM IDN_CLAIM_DIALECT WHERE (ID) IN (SELECT ID FROM DELETED);
  ;
  GO
  
  CREATE OR ALTER TRIGGER TRG_DEL_IDN_CLAIM on IDN_CLAIM
    INSTEAD OF DELETE
       AS 
        BEGIN
          DELETE ICPR FROM DELETED, IDN_CLAIM_PROPERTY ICPR WHERE ICPR.LOCAL_CLAIM_ID = DELETED.ID
          DELETE ICMA FROM DELETED, IDN_CLAIM_MAPPED_ATTRIBUTE ICMA WHERE ICMA.LOCAL_CLAIM_ID = DELETED.ID
          DELETE ICM01 FROM DELETED, IDN_CLAIM_MAPPING ICM01 WHERE ICM01.EXT_CLAIM_ID = DELETED.ID
          DELETE ICM02 FROM DELETED, IDN_CLAIM_MAPPING ICM02 WHERE ICM02.MAPPED_LOCAL_CLAIM_ID = DELETED.ID
  	      DELETE IOSCM FROM DELETED, IDN_OIDC_SCOPE_CLAIM_MAPPING IOSCM WHERE IOSCM.EXTERNAL_CLAIM_ID = DELETED.ID
        END
        DELETE FROM IDN_CLAIM WHERE (ID) IN (SELECT ID FROM DELETED);
  ;
  GO
  
  CREATE OR ALTER TRIGGER TRG_DEL_IDN_AUTH_CODE on IDN_OAUTH2_AUTHORIZATION_CODE
    INSTEAD OF DELETE
       AS 
        BEGIN
          DELETE IOROR FROM DELETED, IDN_OIDC_REQ_OBJECT_REFERENCE IOROR WHERE IOROR.CODE_ID = DELETED.CODE_ID
        END
        DELETE FROM IDN_OAUTH2_AUTHORIZATION_CODE WHERE (CODE_ID) IN (SELECT CODE_ID FROM DELETED);
  ;
  GO
  
  CREATE OR ALTER TRIGGER TRG_DEL_IDN_REQ_OBJ_REF on IDN_OIDC_REQ_OBJECT_REFERENCE
    INSTEAD OF DELETE
       AS 
        BEGIN
          DELETE IOROC FROM DELETED, IDN_OIDC_REQ_OBJECT_CLAIMS IOROC WHERE IOROC.REQ_OBJECT_ID = DELETED.ID
        END
        DELETE FROM IDN_OIDC_REQ_OBJECT_REFERENCE WHERE (ID) IN (SELECT ID FROM DELETED);
  ;
  GO
  
  CREATE OR ALTER TRIGGER TRG_DEL_IDN_OIDC_OBJ_CLAIMS on IDN_OIDC_REQ_OBJECT_CLAIMS
    INSTEAD OF DELETE
       AS 
        BEGIN
          DELETE IOROCV FROM DELETED, IDN_OIDC_REQ_OBJ_CLAIM_VALUES IOROCV WHERE IOROCV.REQ_OBJECT_CLAIMS_ID = DELETED.ID
        END
        DELETE FROM IDN_OIDC_REQ_OBJECT_CLAIMS WHERE (ID) IN (SELECT ID FROM DELETED);
  ;
  GO
  
  CREATE OR ALTER TRIGGER TRG_DEL_IDN_OIDC_SCOPE on IDN_OIDC_SCOPE
    INSTEAD OF DELETE
       AS 
        BEGIN
          DELETE IOSCM FROM DELETED, IDN_OIDC_SCOPE_CLAIM_MAPPING IOSCM WHERE IOSCM.SCOPE_ID = DELETED.ID
        END
        DELETE FROM IDN_OIDC_SCOPE WHERE (ID) IN (SELECT ID FROM DELETED);
  ;
  GO
  
  CREATE OR ALTER TRIGGER TRG_DEL_AM_SUBSCRIBER on AM_SUBSCRIBER
    INSTEAD OF DELETE
       AS 
        BEGIN
          DELETE AMA FROM DELETED, AM_APPLICATION AMA WHERE AMA.SUBSCRIBER_ID = DELETED.SUBSCRIBER_ID
          DELETE AMAR FROM DELETED, AM_API_RATINGS AMAR WHERE AMAR.SUBSCRIBER_ID = DELETED.SUBSCRIBER_ID
        END
        DELETE FROM AM_SUBSCRIBER WHERE (SUBSCRIBER_ID) IN (SELECT SUBSCRIBER_ID FROM DELETED);
  ;
  GO
  
  CREATE OR ALTER TRIGGER TRG_DEL_AM_API on AM_API
    INSTEAD OF DELETE
       AS 
        BEGIN
          DELETE AMSU FROM DELETED, AM_SUBSCRIPTION AMSU WHERE AMSU.API_ID = DELETED.API_ID
          DELETE AMLE FROM DELETED, AM_API_LC_EVENT AMLE WHERE AMLE.API_ID = DELETED.API_ID
          DELETE AMAC FROM DELETED, AM_API_COMMENTS AMAC WHERE AMAC.API_ID = DELETED.API_ID
          DELETE AMAR FROM DELETED, AM_API_RATINGS AMAR WHERE AMAR.API_ID = DELETED.API_ID
          DELETE AMES FROM DELETED, AM_EXTERNAL_STORES AMES WHERE AMES.API_ID = DELETED.API_ID
          DELETE AMS FROM DELETED, AM_API_SCOPES AMS WHERE AMS.API_ID = DELETED.API_ID
  	      DELETE AAPM FROM DELETED, AM_API_PRODUCT_MAPPING AAPM WHERE AAPM.API_ID = DELETED.API_ID
  	      DELETE AACC FROM DELETED, AM_API_CLIENT_CERTIFICATE AACC WHERE AACC.API_ID = DELETED.API_ID
        END
        DELETE FROM AM_API WHERE (API_ID) IN (SELECT API_ID FROM DELETED);
  ;
  GO
  
  CREATE OR ALTER TRIGGER TRG_DEL_AM_API_URL_MAPPING on AM_API_URL_MAPPING
    INSTEAD OF DELETE
       AS 
        BEGIN
          DELETE AAPM FROM DELETED, AM_API_PRODUCT_MAPPING AAPM WHERE AAPM.URL_MAPPING_ID = DELETED.URL_MAPPING_ID
        END
        DELETE FROM AM_API_URL_MAPPING WHERE (URL_MAPPING_ID) IN (SELECT URL_MAPPING_ID FROM DELETED);
  ;
  GO
  
  CREATE or ALTER TRIGGER TRG_DEL_AM_APPLICATION on AM_APPLICATION
    INSTEAD OF DELETE
       AS 
        BEGIN
          DELETE AMSU FROM DELETED, AM_SUBSCRIPTION AMSU WHERE AMSU.APPLICATION_ID = DELETED.APPLICATION_ID
          DELETE AMKM FROM DELETED, AM_APPLICATION_KEY_MAPPING AMKM WHERE AMKM.APPLICATION_ID = DELETED.APPLICATION_ID
          DELETE AMAR FROM DELETED, AM_APPLICATION_REGISTRATION AMAR WHERE AMAR.APP_ID = DELETED.APPLICATION_ID
          DELETE AMGM FROM DELETED, AM_APPLICATION_GROUP_MAPPING AMGM WHERE AMGM.APPLICATION_ID = DELETED.APPLICATION_ID
  	     DELETE AAA FROM DELETED, AM_APPLICATION_ATTRIBUTES AAA WHERE AAA.APPLICATION_ID = DELETED.APPLICATION_ID
        END
        DELETE FROM AM_APPLICATION WHERE (APPLICATION_ID) IN (SELECT APPLICATION_ID FROM DELETED);
  ;
  GO
  
  
  
  CREATE OR ALTER TRIGGER TRG_DEL_AM_API_THROTTLE_POLICY on AM_API_THROTTLE_POLICY
    INSTEAD OF DELETE
       AS 
        BEGIN
          DELETE AMCG FROM DELETED, AM_CONDITION_GROUP AMCG WHERE AMCG.POLICY_ID = DELETED.POLICY_ID
        END
        DELETE FROM AM_API_THROTTLE_POLICY WHERE (POLICY_ID) IN (SELECT POLICY_ID FROM DELETED);
  ;
  GO
  
  CREATE OR ALTER TRIGGER TRG_DEL_AM_CONDITION_GROUP on AM_CONDITION_GROUP
    INSTEAD OF DELETE
       AS 
        BEGIN
          DELETE AMQPC FROM DELETED, AM_QUERY_PARAMETER_CONDITION AMQPC WHERE AMQPC.CONDITION_GROUP_ID = DELETED.CONDITION_GROUP_ID
          DELETE AMHFC FROM DELETED, AM_HEADER_FIELD_CONDITION AMHFC WHERE AMHFC.CONDITION_GROUP_ID = DELETED.CONDITION_GROUP_ID
          DELETE AMJCC FROM DELETED, AM_JWT_CLAIM_CONDITION AMJCC WHERE AMJCC.CONDITION_GROUP_ID = DELETED.CONDITION_GROUP_ID
          DELETE AMIC FROM DELETED, AM_IP_CONDITION AMIC WHERE AMIC.CONDITION_GROUP_ID = DELETED.CONDITION_GROUP_ID
        END
        DELETE FROM AM_CONDITION_GROUP WHERE (CONDITION_GROUP_ID) IN (SELECT CONDITION_GROUP_ID FROM DELETED);
  ;  
  GO
  
  CREATE OR ALTER TRIGGER TRG_DEL_AM_LABELS on AM_LABELS
    INSTEAD OF DELETE
       AS 
        BEGIN
          DELETE ALU FROM DELETED, AM_LABEL_URLS ALU WHERE ALU.LABEL_ID = DELETED.LABEL_ID
        END
        DELETE FROM AM_LABELS WHERE (LABEL_ID) IN (SELECT LABEL_ID FROM DELETED);
  ;
  GO
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AM_SCOPE]') AND TYPE IN (N'U'))
  CREATE TABLE AM_SCOPE (
    SCOPE_ID INTEGER IDENTITY (1,1),
    NAME VARCHAR(255) NOT NULL,
    DISPLAY_NAME VARCHAR(255) NOT NULL,
    DESCRIPTION VARCHAR(512),
    TENANT_ID INTEGER NOT NULL DEFAULT -1,
    PRIMARY KEY (SCOPE_ID)
  );
  
  IF NOT  EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AM_SCOPE_BINDING]') AND TYPE IN (N'U'))
  CREATE TABLE AM_SCOPE_BINDING (
    SCOPE_ID INTEGER NOT NULL,
    SCOPE_BINDING VARCHAR(255),
    FOREIGN KEY (SCOPE_ID) REFERENCES AM_SCOPE(SCOPE_ID)
  );
  
  --Permance indexes start--
  
  create index IDX_ITS_LMT on IDN_THRIFT_SESSION (LAST_MODIFIED_TIME);
  create index IDX_IOAT_UT on IDN_OAUTH2_ACCESS_TOKEN (USER_TYPE);
  create index IDX_AAI_CTX on AM_API (CONTEXT);
  create index IDX_AAKM_CK on AM_APPLICATION_KEY_MAPPING (CONSUMER_KEY);
  create index IDX_AAUM_AI on AM_API_URL_MAPPING (API_ID);
  create index IDX_AAPM_AI on AM_API_PRODUCT_MAPPING (API_ID);
  create index IDX_AAUM_TT on AM_API_URL_MAPPING (THROTTLING_TIER);
  create index IDX_AATP_DQT on AM_API_THROTTLE_POLICY (DEFAULT_QUOTA_TYPE);
  create index IDX_ACG_QT on AM_CONDITION_GROUP (QUOTA_TYPE);
  create index IDX_APS_QT on AM_POLICY_SUBSCRIPTION (QUOTA_TYPE);
  create index IDX_AS_AITIAI on AM_SUBSCRIPTION (API_ID,TIER_ID,APPLICATION_ID);
  create index IDX_APA_QT on AM_POLICY_APPLICATION (QUOTA_TYPE);
  create index IDX_AA_AT_CB on AM_APPLICATION (APPLICATION_TIER,CREATED_BY);
  
  -- Performance indexes end--
  ----- Table insertions start -------------------
  
  INSERT INTO IDN_BASE_TABLE values ('WSO2 Identity Server');
  
  INSERT INTO CM_PURPOSE (NAME, DESCRIPTION, PURPOSE_GROUP, GROUP_TYPE, TENANT_ID) VALUES ('DEFAULT', 'For core functionalities of the product', 'DEFAULT', 'SP', '-1234');
  
  INSERT INTO CM_PURPOSE_CATEGORY (NAME, DESCRIPTION, TENANT_ID) VALUES ('DEFAULT','For core functionalities of the product', '-1234');
  
  INSERT INTO AM_ALERT_TYPES (ALERT_TYPE_NAME, STAKE_HOLDER) VALUES ('AbnormalResponseTime', 'publisher');
  
  INSERT INTO AM_ALERT_TYPES (ALERT_TYPE_NAME, STAKE_HOLDER) VALUES ('AbnormalBackendTime', 'publisher');
  
  INSERT INTO AM_ALERT_TYPES (ALERT_TYPE_NAME, STAKE_HOLDER) VALUES ('AbnormalRequestsPerMin', 'subscriber');
  
  INSERT INTO AM_ALERT_TYPES (ALERT_TYPE_NAME, STAKE_HOLDER) VALUES ('AbnormalRequestPattern', 'subscriber');
  
  INSERT INTO AM_ALERT_TYPES (ALERT_TYPE_NAME, STAKE_HOLDER) VALUES ('UnusualIPAccess', 'subscriber');
  
  INSERT INTO AM_ALERT_TYPES (ALERT_TYPE_NAME, STAKE_HOLDER) VALUES ('FrequentTierLimitHitting', 'subscriber');
  
  INSERT INTO AM_ALERT_TYPES (ALERT_TYPE_NAME, STAKE_HOLDER) VALUES ('ApiHealthMonitor', 'publisher');
  
  ------ Tables insertions End -----------------------