From 79325ac52aeb38b8b9170e78472fd8d058574a8c Mon Sep 17 00:00:00 2001 From: Chatura Dilan Date: Tue, 6 Dec 2016 15:16:37 +0530 Subject: [PATCH] Creating APPM datasources --- modules/core/distribution/pom.xml | 28 + .../core/distribution/src/assembly/bin.xml | 24 +- .../src/repository/conf/app-manager.xml | 4 +- .../conf/datasources/master-datasources.xml | 22 + .../dbscripts/appmgt/h2-sample-data.sql | 61 ++ .../resources/dbscripts/appmgt/h2.sql | 304 +++++++++ .../resources/dbscripts/appmgt/mssql.sql | 394 +++++++++++ .../resources/dbscripts/appmgt/mysql.sql | 307 +++++++++ .../resources/dbscripts/appmgt/oracle.sql | 625 ++++++++++++++++++ .../resources/dbscripts/appmgt/postgresql.sql | 310 +++++++++ 10 files changed, 2071 insertions(+), 8 deletions(-) create mode 100644 modules/core/distribution/src/repository/resources/dbscripts/appmgt/h2-sample-data.sql create mode 100644 modules/core/distribution/src/repository/resources/dbscripts/appmgt/h2.sql create mode 100644 modules/core/distribution/src/repository/resources/dbscripts/appmgt/mssql.sql create mode 100644 modules/core/distribution/src/repository/resources/dbscripts/appmgt/mysql.sql create mode 100644 modules/core/distribution/src/repository/resources/dbscripts/appmgt/oracle.sql create mode 100644 modules/core/distribution/src/repository/resources/dbscripts/appmgt/postgresql.sql diff --git a/modules/core/distribution/pom.xml b/modules/core/distribution/pom.xml index 5ebb3cd8..9effc12d 100644 --- a/modules/core/distribution/pom.xml +++ b/modules/core/distribution/pom.xml @@ -175,6 +175,34 @@ + + + create-app-mgt-schema + package + + run + + + + + + + + + + + + + + + + + + + + + + create-JAGH2-schema diff --git a/modules/core/distribution/src/assembly/bin.xml b/modules/core/distribution/src/assembly/bin.xml index 7409ff54..7aa807ce 100644 --- a/modules/core/distribution/src/assembly/bin.xml +++ b/modules/core/distribution/src/assembly/bin.xml @@ -822,6 +822,15 @@ true 644 + + + ../p2-profile-gen/target/wso2carbon-core-${carbon.kernel.version}/repository/conf/identity/application-authentication.xml + + ${pom.artifactId}-${pom.version}/repository/conf/identity + + true + 644 + src/repository/conf/application-authenticators.xml @@ -842,12 +851,6 @@ 644 - - src/repository/conf/identity/application-authentication.xml - ${pom.artifactId}-${pom.version}/repository/conf/identity - - 644 - src/repository/conf/identity/thrift-authentication.xml ${pom.artifactId}-${pom.version}/repository/conf/identity @@ -1033,6 +1036,15 @@ WSO2AM_DB.h2.db 644 + + + + target/wso2carbon-core-${carbon.kernel.version}/repository/database/WSO2APPM_DB.h2.db + + ${pom.artifactId}-${pom.version}/repository/database + WSO2APPM_DB.h2.db + 644 + diff --git a/modules/core/distribution/src/repository/conf/app-manager.xml b/modules/core/distribution/src/repository/conf/app-manager.xml index 53552cfe..106046b4 100644 --- a/modules/core/distribution/src/repository/conf/app-manager.xml +++ b/modules/core/distribution/src/repository/conf/app-manager.xml @@ -6,7 +6,7 @@ JNDI name of the data source to be used by the app management components such as store, publisher, gateway This data source should be defined in the master-datasources.xml file in conf/datasources directory. --> - jdbc/WSO2AM_DB + jdbc/WSO2APPM_DB jdbc/ES_Storage @@ -163,7 +163,7 @@ This data source is used to write/read UI Activity changes (eg: App Hit count) to seperate database. When using DAS to analyze the changes it needs to configure this data source appropriately. --> - jdbc/WSO2AM_DB + jdbc/WSO2APPM_DB IDN_OAUTH_CONSUMER_APPS(CONSUMER_KEY) and (SAML2_SSO_ISSUER) --> APM_APP(SAML2_SSO_ISSUER) +CREATE TABLE APM_API_CONSUMER_APPS( + ID INTEGER, + SAML2_SSO_ISSUER VARCHAR2(500), + APP_CONSUMER_KEY VARCHAR2(512), + API_TOKEN_ENDPOINT VARCHAR2(1024), + API_CONSUMER_KEY VARCHAR2(512), + API_CONSUMER_SECRET VARCHAR2(512), + APP_NAME VARCHAR2(512), + PRIMARY KEY (ID, APP_CONSUMER_KEY) +) +/ + +CREATE SEQUENCE APM_API_CONSUMER_APPS_SEQ START WITH 1 INCREMENT BY 1 NOCACHE +/ + +CREATE OR REPLACE TRIGGER APM_API_CONSUMER_APPS_TRG + BEFORE INSERT + ON APM_API_CONSUMER_APPS + REFERENCING NEW AS NEW + FOR EACH ROW + BEGIN + SELECT APM_API_CONSUMER_APPS_SEQ.nextval INTO :NEW.ID FROM dual; + END; + / + + + + +CREATE TABLE APM_APP_HITS ( + UUID VARCHAR2(500) NOT NULL, + APP_NAME VARCHAR2(200) NOT NULL, + VERSION VARCHAR2(50), + CONTEXT VARCHAR2(256) NOT NULL, + USER_ID VARCHAR2(50) NOT NULL, + TENANT_ID INTEGER, + HIT_TIME TIMESTAMP NOT NULL, + PRIMARY KEY (UUID, USER_ID, TENANT_ID, HIT_TIME) +) +/ + +CREATE TABLE APM_APP_JAVA_POLICY( + JAVA_POLICY_ID INTEGER, + DISPLAY_NAME VARCHAR2(100) NOT NULL, + FULL_QUALIFI_NAME VARCHAR2(256) NOT NULL, + DESCRIPTION VARCHAR2(2500), + DISPLAY_ORDER_SEQ_NO INTEGER NOT NULL, + IS_MANDATORY NUMBER(1) DEFAULT 0, + POLICY_PROPERTIES VARCHAR2(512) NULL, + IS_GLOBAL NUMBER(1) DEFAULT 1, + PRIMARY KEY(JAVA_POLICY_ID), + UNIQUE(FULL_QUALIFI_NAME,DISPLAY_ORDER_SEQ_NO) +) +/ + +CREATE SEQUENCE APM_APP_JAVA_POLICY_SEQ START WITH 1 INCREMENT BY 1 NOCACHE +/ + +CREATE OR REPLACE TRIGGER APM_APP_JAVA_POLICY_TRG + BEFORE INSERT + ON APM_APP_JAVA_POLICY + REFERENCING NEW AS NEW + FOR EACH ROW + BEGIN + SELECT APM_APP_JAVA_POLICY_SEQ.nextval INTO :NEW.JAVA_POLICY_ID FROM dual; + END; + / + +CREATE TABLE APM_APP_JAVA_POLICY_MAPPING( + JAVA_POLICY_ID INTEGER NOT NULL, + APP_ID INTEGER NOT NULL, + PRIMARY KEY (JAVA_POLICY_ID,APP_ID), + FOREIGN KEY (JAVA_POLICY_ID) REFERENCES APM_APP_JAVA_POLICY(JAVA_POLICY_ID) ON DELETE CASCADE, + FOREIGN KEY (APP_ID) REFERENCES APM_APP(APP_ID) ON DELETE CASCADE +) +/ + +CREATE TABLE APM_EXTERNAL_STORES ( + APP_STORE_ID INTEGER, + APP_ID INTEGER, + STORE_ID VARCHAR2(255) NOT NULL, + FOREIGN KEY(APP_ID) REFERENCES APM_APP(APP_ID) ON DELETE CASCADE, + PRIMARY KEY (APP_STORE_ID) +) +/ + +CREATE SEQUENCE APM_EXTERNAL_STORES_SEQ START WITH 1 INCREMENT BY 1 +/ + +CREATE OR REPLACE TRIGGER APM_EXTERNAL_STORES_TRG + BEFORE INSERT + ON APM_EXTERNAL_STORES + REFERENCING NEW AS NEW + FOR EACH ROW + BEGIN + SELECT APM_EXTERNAL_STORES_SEQ.nextval INTO :NEW.APP_STORE_ID FROM dual; + END; +/ + +CREATE TABLE APM_APP_DEFAULT_VERSION ( + DEFAULT_VERSION_ID INTEGER, + APP_NAME VARCHAR2(256), + APP_PROVIDER VARCHAR2(256), + DEFAULT_APP_VERSION VARCHAR2(30), + PUBLISHED_DEFAULT_APP_VERSION VARCHAR2(30), + TENANT_ID INTEGER, +PRIMARY KEY(DEFAULT_VERSION_ID) +) +/ + +CREATE SEQUENCE APM_APP_DEFAULT_VERSION_SEQ START WITH 1 INCREMENT BY 1 +/ + +CREATE OR REPLACE TRIGGER APM_APP_DEFAULT_VERSION_TRG + BEFORE INSERT + ON APM_APP_DEFAULT_VERSION + REFERENCING NEW AS NEW + FOR EACH ROW + BEGIN + SELECT APM_APP_DEFAULT_VERSION_SEQ.nextval INTO :NEW.DEFAULT_VERSION_ID FROM dual; + END; +/ + +CREATE TABLE APM_FAVOURITE_APPS ( + ID INTEGER , + USER_ID VARCHAR(50) NOT NULL, + TENANT_ID INTEGER NOT NULL, + APP_ID INTEGER NOT NULL, + CREATED_TIME DATE NOT NULL, + PRIMARY KEY (ID), + FOREIGN KEY(APP_ID) REFERENCES APM_APP(APP_ID) ON DELETE CASCADE, + UNIQUE (TENANT_ID,USER_ID,APP_ID) +) +/ + +CREATE SEQUENCE APM_FAVOURITE_APPS_SEQ START WITH 1 INCREMENT BY 1 NOCACHE +/ + +CREATE OR REPLACE TRIGGER APM_FAVOURITE_APPS_TRG + BEFORE INSERT + ON APM_FAVOURITE_APPS + REFERENCING NEW AS NEW + FOR EACH ROW + BEGIN + SELECT APM_FAVOURITE_APPS_SEQ.nextval INTO :NEW.ID FROM dual; + END; +/ + +CREATE TABLE APM_STORE_FAVOURITE_PAGE ( + ID INTEGER , + USER_ID VARCHAR(50) NOT NULL, + TENANT_ID_OF_USER INTEGER NOT NULL, + TENANT_ID_OF_STORE INTEGER NOT NULL, + PRIMARY KEY (ID) +) +/ + +CREATE SEQUENCE APM_STORE_FAVOURITE_PAGE_SEQ START WITH 1 INCREMENT BY 1 NOCACHE +/ + +CREATE OR REPLACE TRIGGER APM_STORE_FAVOURITE_PAGE_TRG + BEFORE INSERT + ON APM_STORE_FAVOURITE_PAGE + REFERENCING NEW AS NEW + FOR EACH ROW + BEGIN + SELECT APM_STORE_FAVOURITE_PAGE_SEQ.nextval INTO :NEW.ID FROM dual; + END; +/ + +CREATE TABLE APM_ONE_TIME_DOWNLOAD_LINK ( + ID INTEGER, + BINARY_FILE VARCHAR(500) NOT NULL, + UUID VARCHAR(500) NOT NULL, + IS_DOWNLOADED NUMBER(1) NOT NULL, + USERNAME VARCHAR(255), + TENANT_ID INTEGER, + TENANT_DOMAIN VARCHAR(255), + CREATED_TIME TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (ID) +) +/ + +CREATE SEQUENCE APM_ONE_TIME_DOWNLOAD_LINK_SEQ START WITH 1 INCREMENT BY 1 NOCACHE +/ + +CREATE OR REPLACE TRIGGER APM_ONE_TIME_DOWNLOAD_LINK_TRG + BEFORE INSERT + ON APM_ONE_TIME_DOWNLOAD_LINK + REFERENCING NEW AS NEW + FOR EACH ROW + BEGIN + SELECT APM_ONE_TIME_DOWNLOAD_LINK_SEQ.nextval INTO :NEW.ID FROM dual; + END; +/ + + +INSERT INTO APM_APP_JAVA_POLICY(DISPLAY_NAME, FULL_QUALIFI_NAME, DESCRIPTION, DISPLAY_ORDER_SEQ_NO,IS_MANDATORY, IS_GLOBAL ) +VALUES ('Reverse Proxy Handler','org.wso2.carbon.appmgt.gateway.handlers.proxy.ReverseProxyHandler','',1,1,1) +/ + +INSERT INTO APM_APP_JAVA_POLICY(DISPLAY_NAME, FULL_QUALIFI_NAME, DESCRIPTION, DISPLAY_ORDER_SEQ_NO,IS_MANDATORY,IS_GLOBAL) +VALUES ('SAML2 Authentication Handler','org.wso2.carbon.appmgt.gateway.handlers.security.authentication.SAML2AuthenticationHandler','',2,1,1) +/ + +INSERT INTO APM_APP_JAVA_POLICY(DISPLAY_NAME, FULL_QUALIFI_NAME, DESCRIPTION, DISPLAY_ORDER_SEQ_NO,IS_MANDATORY,IS_GLOBAL) +VALUES ('Subscription Handler', 'org.wso2.carbon.appmgt.gateway.handlers.subscription.SubscriptionsHandler','',3,1,1) +/ + +INSERT INTO APM_APP_JAVA_POLICY(DISPLAY_NAME, FULL_QUALIFI_NAME, DESCRIPTION, DISPLAY_ORDER_SEQ_NO,IS_MANDATORY,IS_GLOBAL) +VALUES ('Authorization Handler', 'org.wso2.carbon.appmgt.gateway.handlers.security.entitlement.AuthorizationHandler','',4,1,1) +/ + +INSERT INTO APM_APP_JAVA_POLICY(DISPLAY_NAME, FULL_QUALIFI_NAME, DESCRIPTION, DISPLAY_ORDER_SEQ_NO,IS_MANDATORY,IS_GLOBAL) +VALUES ('Entitlement Handler','org.wso2.carbon.appmgt.gateway.handlers.security.entitlement.EntitlementHandler','',5,1,1) +/ + +INSERT INTO APM_APP_JAVA_POLICY(DISPLAY_NAME, FULL_QUALIFI_NAME, DESCRIPTION, DISPLAY_ORDER_SEQ_NO,IS_MANDATORY, POLICY_PROPERTIES,IS_GLOBAL ) +VALUES ('API Throttle Handler','org.wso2.carbon.appmgt.gateway.handlers.throttling.APIThrottleHandler','',6,1,'{ "id": "A", "policyKey": "gov:/appmgt/applicationdata/tiers.xml"}',1) +/ + +INSERT INTO APM_APP_JAVA_POLICY(DISPLAY_NAME, FULL_QUALIFI_NAME, DESCRIPTION, DISPLAY_ORDER_SEQ_NO,IS_MANDATORY,IS_GLOBAL) +VALUES ('Publish Statistics:','org.wso2.carbon.appmgt.usage.publisher.APPMgtUsageHandler','',7,0,1) +/ + + diff --git a/modules/core/distribution/src/repository/resources/dbscripts/appmgt/postgresql.sql b/modules/core/distribution/src/repository/resources/dbscripts/appmgt/postgresql.sql new file mode 100644 index 00000000..6798fc83 --- /dev/null +++ b/modules/core/distribution/src/repository/resources/dbscripts/appmgt/postgresql.sql @@ -0,0 +1,310 @@ +BEGIN TRANSACTION; + +CREATE TABLE IF NOT EXISTS IDN_BASE_TABLE ( + PRODUCT_NAME VARCHAR (20), + PRIMARY KEY (PRODUCT_NAME) +) +; + +INSERT INTO IDN_BASE_TABLE values ('WSO2 Identity Server'); + +CREATE TABLE IF NOT EXISTS IDN_OAUTH_CONSUMER_APPS ( + CONSUMER_KEY VARCHAR (512), + CONSUMER_SECRET VARCHAR (512), + USERNAME VARCHAR (255), + TENANT_ID INTEGER DEFAULT 0, + APP_NAME VARCHAR (255), + OAUTH_VERSION VARCHAR (128), + CALLBACK_URL VARCHAR (1024), + GRANT_TYPES VARCHAR (1024), + PRIMARY KEY (CONSUMER_KEY) +) +; + +CREATE TABLE IF NOT EXISTS IDN_OAUTH1A_REQUEST_TOKEN ( + REQUEST_TOKEN VARCHAR (512), + REQUEST_TOKEN_SECRET VARCHAR (512), + CONSUMER_KEY VARCHAR (512), + CALLBACK_URL VARCHAR (1024), + SCOPE VARCHAR(2048), + AUTHORIZED VARCHAR (128), + OAUTH_VERIFIER VARCHAR (512), + AUTHZ_USER VARCHAR (512), + PRIMARY KEY (REQUEST_TOKEN), + FOREIGN KEY (CONSUMER_KEY) REFERENCES IDN_OAUTH_CONSUMER_APPS(CONSUMER_KEY) +) +; + +CREATE TABLE IF NOT EXISTS IDN_OAUTH1A_ACCESS_TOKEN ( + ACCESS_TOKEN VARCHAR (512), + ACCESS_TOKEN_SECRET VARCHAR (512), + CONSUMER_KEY VARCHAR (512), + SCOPE VARCHAR(2048), + AUTHZ_USER VARCHAR (512), + PRIMARY KEY (ACCESS_TOKEN), + FOREIGN KEY (CONSUMER_KEY) REFERENCES IDN_OAUTH_CONSUMER_APPS(CONSUMER_KEY) +) +; + +CREATE TABLE IF NOT EXISTS IDN_OAUTH2_AUTHORIZATION_CODE ( + AUTHORIZATION_CODE VARCHAR (512), + CONSUMER_KEY VARCHAR (512), + SCOPE VARCHAR(2048), + AUTHZ_USER VARCHAR (512), + TIME_CREATED TIMESTAMP, + VALIDITY_PERIOD BIGINT, + PRIMARY KEY (AUTHORIZATION_CODE), + FOREIGN KEY (CONSUMER_KEY) REFERENCES IDN_OAUTH_CONSUMER_APPS(CONSUMER_KEY) +) +; + +CREATE TABLE IF NOT EXISTS IDN_OAUTH2_ACCESS_TOKEN ( + ACCESS_TOKEN VARCHAR (255), + REFRESH_TOKEN VARCHAR (255), + CONSUMER_KEY VARCHAR (255), + AUTHZ_USER VARCHAR (255), + USER_TYPE VARCHAR (255), + TIME_CREATED TIMESTAMP, + VALIDITY_PERIOD BIGINT, + TOKEN_SCOPE VARCHAR (25), + TOKEN_STATE VARCHAR (25) DEFAULT 'ACTIVE', + TOKEN_STATE_ID VARCHAR (255) DEFAULT 'NONE', + PRIMARY KEY (ACCESS_TOKEN), + FOREIGN KEY (CONSUMER_KEY) REFERENCES IDN_OAUTH_CONSUMER_APPS(CONSUMER_KEY) +) +; + +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) +) +; + +CREATE SEQUENCE AM_SUBSCRIBER_SEQUENCE START WITH 1 INCREMENT BY 1; +CREATE TABLE IF NOT EXISTS AM_SUBSCRIBER ( + SUBSCRIBER_ID INTEGER DEFAULT nextval('am_subscriber_sequence'), + USER_ID VARCHAR(50) NOT NULL, + TENANT_ID INTEGER NOT NULL, + EMAIL_ADDRESS VARCHAR(256) NULL, + DATE_SUBSCRIBED DATE NOT NULL, + PRIMARY KEY (SUBSCRIBER_ID), + UNIQUE (TENANT_ID,USER_ID) +) +; + +CREATE SEQUENCE AM_APPLICATION_SEQUENCE START WITH 1 INCREMENT BY 1 ; +CREATE TABLE IF NOT EXISTS AM_APPLICATION ( + APPLICATION_ID INTEGER DEFAULT nextval('am_application_sequence'), + NAME VARCHAR(100), + SUBSCRIBER_ID INTEGER, + APPLICATION_TIER VARCHAR(50) DEFAULT 'Unlimited', + CALLBACK_URL VARCHAR(512), + DESCRIPTION VARCHAR(512), + APPLICATION_STATUS VARCHAR(50) DEFAULT 'APPROVED', + FOREIGN KEY(SUBSCRIBER_ID) REFERENCES AM_SUBSCRIBER(SUBSCRIBER_ID) ON UPDATE CASCADE ON DELETE RESTRICT, + PRIMARY KEY(APPLICATION_ID), + UNIQUE (NAME,SUBSCRIBER_ID) +) +; + +CREATE SEQUENCE APM_BUSINESS_OWNER_SEQUENCE START WITH 1 INCREMENT BY 1 ; +CREATE TABLE IF NOT EXISTS APM_BUSINESS_OWNER( + OWNER_ID INTEGER DEFAULT nextval('apm_business_owner_sequence'), + OWNER_NAME VARCHAR(200) NOT NULL, + OWNER_EMAIL VARCHAR(300) NOT NULL, + OWNER_DESC VARCHAR(1500), + OWNER_SITE VARCHAR(200), + TENANT_ID INTEGER, + PRIMARY KEY(OWNER_ID), + UNIQUE (OWNER_NAME,OWNER_EMAIL,TENANT_ID) + +); + +CREATE SEQUENCE APM_BUSINESS_OWNER_PROPERTY_SEQUENCE START WITH 1 INCREMENT BY 1 ; +CREATE TABLE IF NOT EXISTS APM_BUSINESS_OWNER_PROPERTY( + OWNER_PROP_ID INTEGER DEFAULT nextval('apm_business_owner_property_sequence'), + OWNER_ID INTEGER NOT NULL, + NAME VARCHAR(200) NOT NULL, + VALUE VARCHAR(300) NOT NULL, + SHOW_IN_STORE BOOLEAN NOT NULL, + PRIMARY KEY(OWNER_PROP_ID), + FOREIGN KEY(OWNER_ID) REFERENCES APM_BUSINESS_OWNER(OWNER_ID) +); + +CREATE SEQUENCE APPMGR_APP_SEQUENCE START WITH 1 INCREMENT BY 1; +CREATE TABLE IF NOT EXISTS APPMGR_APP ( + API_ID INTEGER DEFAULT nextval('appmgr_app_sequence'), + API_PROVIDER VARCHAR(256), + API_NAME VARCHAR(256), + API_VERSION VARCHAR(30), + CONTEXT VARCHAR(256), + PRIMARY KEY(API_ID), + UNIQUE (API_PROVIDER,API_NAME,API_VERSION) +) +; + +CREATE SEQUENCE APPMGR_APP_URL_MAPPING_SEQUENCE START WITH 1 INCREMENT BY 1; +CREATE TABLE IF NOT EXISTS APPMGR_APP_URL_MAPPING ( + URL_MAPPING_ID INTEGER DEFAULT nextval('appmgr_app_url_mapping_sequence'), + 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, + USER_ROLES varchar(512) DEFAULT NULL, + ENTITLEMENT_POLICY_ID varchar(512) DEFAULT NULL, + PRIMARY KEY(URL_MAPPING_ID) +) +; + +CREATE SEQUENCE AM_SUBSCRIPTION_SEQUENCE START WITH 1 INCREMENT BY 1; +CREATE TABLE IF NOT EXISTS AM_SUBSCRIPTION ( + SUBSCRIPTION_ID INTEGER DEFAULT nextval('am_subscription_sequence'), + SUBSCRIPTION_TYPE VARCHAR(50), + TIER_ID VARCHAR(50), + API_ID INTEGER, + LAST_ACCESSED DATE NULL, + APPLICATION_ID INTEGER, + SUB_STATUS VARCHAR(50), + FOREIGN KEY(APPLICATION_ID) REFERENCES AM_APPLICATION(APPLICATION_ID) ON UPDATE CASCADE ON DELETE RESTRICT, + FOREIGN KEY(API_ID) REFERENCES APPMGR_APP(API_ID) ON UPDATE CASCADE ON DELETE RESTRICT, + PRIMARY KEY (SUBSCRIPTION_ID) +) +; + +CREATE TABLE IF NOT EXISTS AM_SUBSCRIPTION_KEY_MAPPING ( + SUBSCRIPTION_ID INTEGER, + ACCESS_TOKEN VARCHAR(512), + KEY_TYPE VARCHAR(512) NOT NULL, + FOREIGN KEY(SUBSCRIPTION_ID) REFERENCES AM_SUBSCRIPTION(SUBSCRIPTION_ID) ON UPDATE CASCADE ON DELETE RESTRICT, + PRIMARY KEY(SUBSCRIPTION_ID,ACCESS_TOKEN) +) +; + +CREATE TABLE IF NOT EXISTS AM_APPLICATION_KEY_MAPPING ( + APPLICATION_ID INTEGER, + CONSUMER_KEY VARCHAR(512), + KEY_TYPE VARCHAR(512) NOT NULL, + FOREIGN KEY(APPLICATION_ID) REFERENCES AM_APPLICATION(APPLICATION_ID) ON UPDATE CASCADE ON DELETE RESTRICT, + PRIMARY KEY(APPLICATION_ID,CONSUMER_KEY) +) +; + +CREATE SEQUENCE APPMGR_APP_LC_EVENT_SEQUENCE START WITH 1 INCREMENT BY 1; +CREATE TABLE IF NOT EXISTS APPMGR_APP_LC_EVENT ( + EVENT_ID INTEGER DEFAULT nextval('appmgr_app_lc_event_sequence'), + 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 DATE NOT NULL, + FOREIGN KEY(API_ID) REFERENCES APPMGR_APP(API_ID) ON UPDATE CASCADE ON DELETE RESTRICT, + PRIMARY KEY (EVENT_ID) +) +; + +CREATE TABLE IF NOT EXISTS AM_APP_KEY_DOMAIN_MAPPING ( + CONSUMER_KEY VARCHAR(255), + AUTHZ_DOMAIN VARCHAR(255) DEFAULT 'ALL', + PRIMARY KEY (CONSUMER_KEY,AUTHZ_DOMAIN), + FOREIGN KEY (CONSUMER_KEY) REFERENCES IDN_OAUTH_CONSUMER_APPS(CONSUMER_KEY) +) +; + +CREATE SEQUENCE APPMGR_APP_COMMENTS_SEQUENCE START WITH 1 INCREMENT BY 1; +CREATE TABLE IF NOT EXISTS APPMGR_APP_COMMENTS ( + COMMENT_ID INTEGER DEFAULT nextval('appmgr_app_comments_sequence'), + COMMENT_TEXT VARCHAR(512), + COMMENTED_USER VARCHAR(255), + DATE_COMMENTED DATE NOT NULL, + API_ID INTEGER NOT NULL, + FOREIGN KEY(API_ID) REFERENCES APPMGR_APP(API_ID) ON UPDATE CASCADE ON DELETE RESTRICT, + PRIMARY KEY (COMMENT_ID) +) +; + +CREATE SEQUENCE AM_WORKFLOWS_SEQUENCE START WITH 1 INCREMENT BY 1; +CREATE TABLE IF NOT EXISTS AM_WORKFLOWS( + WF_ID INTEGER DEFAULT nextval('am_workflows_sequence'), + WF_REFERENCE VARCHAR(255) NOT NULL, + WF_TYPE VARCHAR(255) NOT NULL, + WF_STATUS VARCHAR(255) NOT NULL, + WF_CREATED_TIME TIMESTAMP, + WF_UPDATED_TIME TIMESTAMP, + WF_STATUS_DESC VARCHAR(1000), + TENANT_ID INTEGER, + TENANT_DOMAIN VARCHAR(255), + WF_EXTERNAL_REFERENCE VARCHAR(255) NOT NULL, + PRIMARY KEY (WF_ID), + UNIQUE (WF_EXTERNAL_REFERENCE) +) +; + +CREATE SEQUENCE APPMGR_APP_RATINGS_SEQUENCE START WITH 1 INCREMENT BY 1; +CREATE TABLE IF NOT EXISTS APPMGR_APP_RATINGS ( + RATING_ID INTEGER DEFAULT nextval('appmgr_app_ratings_sequence'), + API_ID INTEGER, + RATING INTEGER, + SUBSCRIBER_ID INTEGER, + FOREIGN KEY(API_ID) REFERENCES APPMGR_APP(API_ID) ON UPDATE CASCADE ON DELETE RESTRICT, + FOREIGN KEY(SUBSCRIBER_ID) REFERENCES AM_SUBSCRIBER(SUBSCRIBER_ID) ON UPDATE CASCADE ON DELETE RESTRICT, + PRIMARY KEY (RATING_ID) +) +; + +CREATE SEQUENCE AM_TIER_PERMISSIONS_SEQUENCE START WITH 1 INCREMENT BY 1; +CREATE TABLE IF NOT EXISTS AM_TIER_PERMISSIONS ( + TIER_PERMISSIONS_ID INTEGER DEFAULT nextval('am_tier_permissions_sequence'), + 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) +); + +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, + PRIMARY KEY (SESSION_ID) + +) +; + +CREATE SEQUENCE AM_EXTERNAL_STORES_SEQUENCE START WITH 1 INCREMENT BY 1; +CREATE TABLE IF NOT EXISTS AM_EXTERNAL_STORES ( + APISTORE_ID INTEGER DEFAULT nextval('am_external_stores_sequence'), + 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, + FOREIGN KEY(API_ID) REFERENCES APPMGR_APP(API_ID) ON UPDATE CASCADE ON DELETE RESTRICT, + PRIMARY KEY (APISTORE_ID) +) +; + +CREATE SEQUENCE APM_APP_DEFAULT_VERSION_SEQUENCE START WITH 1 INCREMENT BY 1; +CREATE TABLE IF NOT EXISTS APM_APP_DEFAULT_VERSION ( + DEFAULT_VERSION_ID INTEGER DEFAULT nextval('apm_app_default_version_sequence'), + APP_NAME VARCHAR(256), + APP_PROVIDER VARCHAR(256), + DEFAULT_APP_VERSION VARCHAR(30), + PUBLISHED_DEFAULT_APP_VERSION VARCHAR(30), + TENANT_ID INTEGER, +PRIMARY KEY(DEFAULT_VERSION_ID) +) +; + +CREATE INDEX IDX_SUB_APP_ID ON AM_SUBSCRIPTION (APPLICATION_ID, SUBSCRIPTION_ID) +; +CREATE INDEX IDX_AT_CK_AU ON IDN_OAUTH2_ACCESS_TOKEN(CONSUMER_KEY, AUTHZ_USER, TOKEN_STATE, USER_TYPE); +commit;