From cb5736854ad97d263e1599a3d744f48dc8fed4d1 Mon Sep 17 00:00:00 2001 From: Dileesha Rajapakse Date: Tue, 10 May 2016 14:58:02 +0530 Subject: [PATCH] Fixed issues in Oracle DB script --- .../main/resources/dbscripts/cdm/oracle.sql | 144 +++++++++++------- 1 file changed, 91 insertions(+), 53 deletions(-) diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql index ab74524c593..3f6d81226bf 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql @@ -2,7 +2,7 @@ CREATE TABLE DM_DEVICE_TYPE ( ID NUMBER(10) NOT NULL, NAME VARCHAR2(300) DEFAULT NULL, PROVIDER_TENANT_ID INTEGER DEFAULT 0, - SHARED_WITH_ALL_TENANTS BOOLEAN NOT NULL DEFAULT FALSE, + SHARED_WITH_ALL_TENANTS NUMBER(1) DEFAULT 0 NOT NULL, CONSTRAINT PK_DM_DEVICE_TYPE PRIMARY KEY (ID) ) / @@ -20,6 +20,31 @@ WHEN (NEW.ID IS NULL) END; / +CREATE TABLE DM_GROUP ( + ID NUMBER(10) NOT NULL, + DESCRIPTION CLOB DEFAULT NULL, + GROUP_NAME VARCHAR2(100) DEFAULT NULL, + DATE_OF_ENROLLMENT TIMESTAMP(0) DEFAULT NULL, + DATE_OF_LAST_UPDATE TIMESTAMP(0) DEFAULT NULL, + OWNER VARCHAR2(45) DEFAULT NULL, + TENANT_ID NUMBER(10) DEFAULT 0, + CONSTRAINT PK_DM_GROUP PRIMARY KEY (ID) +) +/ +-- Generate ID using sequence and trigger +CREATE SEQUENCE DM_GROUP_seq START WITH 1 INCREMENT BY 1 NOCACHE +/ +CREATE OR REPLACE TRIGGER DM_GROUP_seq_tr +BEFORE INSERT +ON DM_GROUP +REFERENCING NEW AS NEW +FOR EACH ROW +WHEN (NEW.ID IS NULL) + BEGIN + SELECT DM_GROUP_seq.NEXTVAL INTO :NEW.ID FROM DUAL; + END; +/ + CREATE TABLE DM_DEVICE_CERTIFICATE ( ID NUMBER(10) NOT NULL, SERIAL_NUMBER VARCHAR2(500) DEFAULT NULL, @@ -65,6 +90,29 @@ WHEN (NEW.ID IS NULL) END; / +CREATE TABLE DM_DEVICE_GROUP_MAP ( + ID NUMBER(10) NOT NULL, + DEVICE_ID NUMBER(10) DEFAULT NULL, + GROUP_ID NUMBER(10) DEFAULT NULL, + TENANT_ID NUMBER(10) DEFAULT 0, + PRIMARY KEY (ID), + CONSTRAINT fk_DM_DEV_GROUP_MAP_DM_DEV2 FOREIGN KEY (DEVICE_ID) + REFERENCES DM_DEVICE (ID), + CONSTRAINT fk_DM_DEV_GROUP_MAP_DM_GROUP2 FOREIGN KEY (GROUP_ID) + REFERENCES DM_GROUP (ID) +); + +-- Generate ID using sequence and trigger +CREATE SEQUENCE DM_DEVICE_GROUP_MAP_seq START WITH 1 INCREMENT BY 1; + +CREATE OR REPLACE TRIGGER DM_DEVICE_GROUP_MAP_seq_tr +BEFORE INSERT ON DM_DEVICE_GROUP_MAP FOR EACH ROW +WHEN (NEW.ID IS NULL) + BEGIN + SELECT DM_DEVICE_GROUP_MAP_seq.NEXTVAL INTO :NEW.ID FROM DUAL; + END; +/ + CREATE TABLE DM_OPERATION ( ID NUMBER(10) NOT NULL, TYPE VARCHAR2(50) NOT NULL, @@ -576,23 +624,23 @@ CREATE TABLE DM_DEVICE_GROUP_POLICY ( TENANT_ID NUMBER(10) NOT NULL, PRIMARY KEY (ID), CONSTRAINT FK_DM_DEVICE_GROUP_POLICY - FOREIGN KEY (DEVICE_GROUP_ID) - REFERENCES DM_GROUP (ID) - , + FOREIGN KEY (DEVICE_GROUP_ID) + REFERENCES DM_GROUP (ID) + , CONSTRAINT FK_DM_DEVICE_GROUP_DM_POLICY - FOREIGN KEY (POLICY_ID) - REFERENCES DM_POLICY (ID) + FOREIGN KEY (POLICY_ID) + REFERENCES DM_POLICY (ID) ) ; -- Generate ID using sequence and trigger CREATE SEQUENCE DM_DEVICE_GROUP_POLICY_seq START WITH 1 INCREMENT BY 1; CREATE OR REPLACE TRIGGER DM_DEVICE_GROUP_POLICY_seq_tr - BEFORE INSERT ON DM_DEVICE_GROUP_POLICY FOR EACH ROW - WHEN (NEW.ID IS NULL) -BEGIN - SELECT DM_DEVICE_GROUP_POLICY_seq.NEXTVAL INTO :NEW.ID FROM DUAL; -END; +BEFORE INSERT ON DM_DEVICE_GROUP_POLICY FOR EACH ROW +WHEN (NEW.ID IS NULL) + BEGIN + SELECT DM_DEVICE_GROUP_POLICY_seq.NEXTVAL INTO :NEW.ID FROM DUAL; + END; / @@ -690,9 +738,9 @@ WHEN (NEW.NOTIFICATION_ID IS NULL) -- Device Info and Search Table -- BEGIN - EXECUTE IMMEDIATE 'DROP TABLE DM_DEVICE_INFO'; -EXCEPTION - WHEN OTHERS THEN NULL; + EXECUTE IMMEDIATE 'DROP TABLE DM_DEVICE_INFO'; + EXCEPTION + WHEN OTHERS THEN NULL; END; / @@ -702,10 +750,10 @@ CREATE TABLE DM_DEVICE_INFO ( KEY_FIELD VARCHAR2(45) NULL, VALUE_FIELD VARCHAR2(100) NULL, PRIMARY KEY (ID) - , + , CONSTRAINT DM_DEVICE_INFO_DEVICE - FOREIGN KEY (DEVICE_ID) - REFERENCES DM_DEVICE (ID) + FOREIGN KEY (DEVICE_ID) + REFERENCES DM_DEVICE (ID) ) ; @@ -713,21 +761,17 @@ CREATE TABLE DM_DEVICE_INFO ( CREATE SEQUENCE DM_DEVICE_INFO_seq START WITH 1 INCREMENT BY 1; CREATE OR REPLACE TRIGGER DM_DEVICE_INFO_seq_tr - BEFORE INSERT ON DM_DEVICE_INFO FOR EACH ROW - WHEN (NEW.ID IS NULL) -BEGIN - SELECT DM_DEVICE_INFO_seq.NEXTVAL INTO :NEW.ID FROM DUAL; -END; +BEFORE INSERT ON DM_DEVICE_INFO FOR EACH ROW +WHEN (NEW.ID IS NULL) + BEGIN + SELECT DM_DEVICE_INFO_seq.NEXTVAL INTO :NEW.ID FROM DUAL; + END; / -CREATE INDEX DM_DEVICE_INFO_DEVICE_idx ON DM_DEVICE_INFO (DEVICE_ID ASC); - - - BEGIN - EXECUTE IMMEDIATE 'DROP TABLE DM_DEVICE_LOCATION'; -EXCEPTION - WHEN OTHERS THEN NULL; + EXECUTE IMMEDIATE 'DROP TABLE DM_DEVICE_LOCATION'; + EXCEPTION + WHEN OTHERS THEN NULL; END; / @@ -744,10 +788,10 @@ CREATE TABLE DM_DEVICE_LOCATION ( COUNTRY VARCHAR2(45) NULL, UPDATE_TIMESTAMP NUMBER(19) NOT NULL, PRIMARY KEY (ID) - , + , CONSTRAINT DM_DEVICE_LOCATION_DEVICE - FOREIGN KEY (DEVICE_ID) - REFERENCES DM_DEVICE (ID) + FOREIGN KEY (DEVICE_ID) + REFERENCES DM_DEVICE (ID) ) ; @@ -755,21 +799,17 @@ CREATE TABLE DM_DEVICE_LOCATION ( CREATE SEQUENCE DM_DEVICE_LOCATION_seq START WITH 1 INCREMENT BY 1; CREATE OR REPLACE TRIGGER DM_DEVICE_LOCATION_seq_tr - BEFORE INSERT ON DM_DEVICE_LOCATION FOR EACH ROW - WHEN (NEW.ID IS NULL) -BEGIN - SELECT DM_DEVICE_LOCATION_seq.NEXTVAL INTO :NEW.ID FROM DUAL; -END; +BEFORE INSERT ON DM_DEVICE_LOCATION FOR EACH ROW +WHEN (NEW.ID IS NULL) + BEGIN + SELECT DM_DEVICE_LOCATION_seq.NEXTVAL INTO :NEW.ID FROM DUAL; + END; / -CREATE INDEX DM_DEVICE_LOCATION_DEVICE_idx ON DM_DEVICE_LOCATION (DEVICE_ID ASC); - - - BEGIN - EXECUTE IMMEDIATE 'DROP TABLE DM_DEVICE_DETAIL'; -EXCEPTION - WHEN OTHERS THEN NULL; + EXECUTE IMMEDIATE 'DROP TABLE DM_DEVICE_DETAIL'; + EXCEPTION + WHEN OTHERS THEN NULL; END; / @@ -793,20 +833,18 @@ CREATE TABLE DM_DEVICE_DETAIL ( UPDATE_TIMESTAMP NUMBER(19) NOT NULL, PRIMARY KEY (ID), CONSTRAINT FK_DM_DEVICE_DETAILS_DEVICE - FOREIGN KEY (DEVICE_ID) - REFERENCES DM_DEVICE (ID) + FOREIGN KEY (DEVICE_ID) + REFERENCES DM_DEVICE (ID) ); -- Generate ID using sequence and trigger CREATE SEQUENCE DM_DEVICE_DETAIL_seq START WITH 1 INCREMENT BY 1; CREATE OR REPLACE TRIGGER DM_DEVICE_DETAIL_seq_tr - BEFORE INSERT ON DM_DEVICE_DETAIL FOR EACH ROW - WHEN (NEW.ID IS NULL) -BEGIN - SELECT DM_DEVICE_DETAIL_seq.NEXTVAL INTO :NEW.ID FROM DUAL; -END; +BEFORE INSERT ON DM_DEVICE_DETAIL FOR EACH ROW +WHEN (NEW.ID IS NULL) + BEGIN + SELECT DM_DEVICE_DETAIL_seq.NEXTVAL INTO :NEW.ID FROM DUAL; + END; / -CREATE INDEX FK_DM_DEVICE_DETAILS_DEVICE_idx ON DM_DEVICE_DETAIL (DEVICE_ID ASC); -