Merge pull request #236 from dilee/master

Fixed issues in Oracle DB script
revert-70aa11f8
Prabath Abeysekara 9 years ago
commit 400f2bb7b4

@ -2,7 +2,7 @@ CREATE TABLE DM_DEVICE_TYPE (
ID NUMBER(10) NOT NULL, ID NUMBER(10) NOT NULL,
NAME VARCHAR2(300) DEFAULT NULL, NAME VARCHAR2(300) DEFAULT NULL,
PROVIDER_TENANT_ID INTEGER DEFAULT 0, 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) CONSTRAINT PK_DM_DEVICE_TYPE PRIMARY KEY (ID)
) )
/ /
@ -20,6 +20,31 @@ WHEN (NEW.ID IS NULL)
END; 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 ( CREATE TABLE DM_DEVICE_CERTIFICATE (
ID NUMBER(10) NOT NULL, ID NUMBER(10) NOT NULL,
SERIAL_NUMBER VARCHAR2(500) DEFAULT NULL, SERIAL_NUMBER VARCHAR2(500) DEFAULT NULL,
@ -65,6 +90,29 @@ WHEN (NEW.ID IS NULL)
END; 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 ( CREATE TABLE DM_OPERATION (
ID NUMBER(10) NOT NULL, ID NUMBER(10) NOT NULL,
TYPE VARCHAR2(50) NOT NULL, TYPE VARCHAR2(50) NOT NULL,
@ -576,23 +624,23 @@ CREATE TABLE DM_DEVICE_GROUP_POLICY (
TENANT_ID NUMBER(10) NOT NULL, TENANT_ID NUMBER(10) NOT NULL,
PRIMARY KEY (ID), PRIMARY KEY (ID),
CONSTRAINT FK_DM_DEVICE_GROUP_POLICY CONSTRAINT FK_DM_DEVICE_GROUP_POLICY
FOREIGN KEY (DEVICE_GROUP_ID) FOREIGN KEY (DEVICE_GROUP_ID)
REFERENCES DM_GROUP (ID) REFERENCES DM_GROUP (ID)
, ,
CONSTRAINT FK_DM_DEVICE_GROUP_DM_POLICY CONSTRAINT FK_DM_DEVICE_GROUP_DM_POLICY
FOREIGN KEY (POLICY_ID) FOREIGN KEY (POLICY_ID)
REFERENCES DM_POLICY (ID) REFERENCES DM_POLICY (ID)
) ; ) ;
-- Generate ID using sequence and trigger -- Generate ID using sequence and trigger
CREATE SEQUENCE DM_DEVICE_GROUP_POLICY_seq START WITH 1 INCREMENT BY 1; CREATE SEQUENCE DM_DEVICE_GROUP_POLICY_seq START WITH 1 INCREMENT BY 1;
CREATE OR REPLACE TRIGGER DM_DEVICE_GROUP_POLICY_seq_tr CREATE OR REPLACE TRIGGER DM_DEVICE_GROUP_POLICY_seq_tr
BEFORE INSERT ON DM_DEVICE_GROUP_POLICY FOR EACH ROW BEFORE INSERT ON DM_DEVICE_GROUP_POLICY FOR EACH ROW
WHEN (NEW.ID IS NULL) WHEN (NEW.ID IS NULL)
BEGIN BEGIN
SELECT DM_DEVICE_GROUP_POLICY_seq.NEXTVAL INTO :NEW.ID FROM DUAL; SELECT DM_DEVICE_GROUP_POLICY_seq.NEXTVAL INTO :NEW.ID FROM DUAL;
END; END;
/ /
@ -690,9 +738,9 @@ WHEN (NEW.NOTIFICATION_ID IS NULL)
-- Device Info and Search Table -- -- Device Info and Search Table --
BEGIN BEGIN
EXECUTE IMMEDIATE 'DROP TABLE DM_DEVICE_INFO'; EXECUTE IMMEDIATE 'DROP TABLE DM_DEVICE_INFO';
EXCEPTION EXCEPTION
WHEN OTHERS THEN NULL; WHEN OTHERS THEN NULL;
END; END;
/ /
@ -702,10 +750,10 @@ CREATE TABLE DM_DEVICE_INFO (
KEY_FIELD VARCHAR2(45) NULL, KEY_FIELD VARCHAR2(45) NULL,
VALUE_FIELD VARCHAR2(100) NULL, VALUE_FIELD VARCHAR2(100) NULL,
PRIMARY KEY (ID) PRIMARY KEY (ID)
, ,
CONSTRAINT DM_DEVICE_INFO_DEVICE CONSTRAINT DM_DEVICE_INFO_DEVICE
FOREIGN KEY (DEVICE_ID) FOREIGN KEY (DEVICE_ID)
REFERENCES DM_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 SEQUENCE DM_DEVICE_INFO_seq START WITH 1 INCREMENT BY 1;
CREATE OR REPLACE TRIGGER DM_DEVICE_INFO_seq_tr CREATE OR REPLACE TRIGGER DM_DEVICE_INFO_seq_tr
BEFORE INSERT ON DM_DEVICE_INFO FOR EACH ROW BEFORE INSERT ON DM_DEVICE_INFO FOR EACH ROW
WHEN (NEW.ID IS NULL) WHEN (NEW.ID IS NULL)
BEGIN BEGIN
SELECT DM_DEVICE_INFO_seq.NEXTVAL INTO :NEW.ID FROM DUAL; SELECT DM_DEVICE_INFO_seq.NEXTVAL INTO :NEW.ID FROM DUAL;
END; END;
/ /
CREATE INDEX DM_DEVICE_INFO_DEVICE_idx ON DM_DEVICE_INFO (DEVICE_ID ASC);
BEGIN BEGIN
EXECUTE IMMEDIATE 'DROP TABLE DM_DEVICE_LOCATION'; EXECUTE IMMEDIATE 'DROP TABLE DM_DEVICE_LOCATION';
EXCEPTION EXCEPTION
WHEN OTHERS THEN NULL; WHEN OTHERS THEN NULL;
END; END;
/ /
@ -744,10 +788,10 @@ CREATE TABLE DM_DEVICE_LOCATION (
COUNTRY VARCHAR2(45) NULL, COUNTRY VARCHAR2(45) NULL,
UPDATE_TIMESTAMP NUMBER(19) NOT NULL, UPDATE_TIMESTAMP NUMBER(19) NOT NULL,
PRIMARY KEY (ID) PRIMARY KEY (ID)
, ,
CONSTRAINT DM_DEVICE_LOCATION_DEVICE CONSTRAINT DM_DEVICE_LOCATION_DEVICE
FOREIGN KEY (DEVICE_ID) FOREIGN KEY (DEVICE_ID)
REFERENCES DM_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 SEQUENCE DM_DEVICE_LOCATION_seq START WITH 1 INCREMENT BY 1;
CREATE OR REPLACE TRIGGER DM_DEVICE_LOCATION_seq_tr CREATE OR REPLACE TRIGGER DM_DEVICE_LOCATION_seq_tr
BEFORE INSERT ON DM_DEVICE_LOCATION FOR EACH ROW BEFORE INSERT ON DM_DEVICE_LOCATION FOR EACH ROW
WHEN (NEW.ID IS NULL) WHEN (NEW.ID IS NULL)
BEGIN BEGIN
SELECT DM_DEVICE_LOCATION_seq.NEXTVAL INTO :NEW.ID FROM DUAL; SELECT DM_DEVICE_LOCATION_seq.NEXTVAL INTO :NEW.ID FROM DUAL;
END; END;
/ /
CREATE INDEX DM_DEVICE_LOCATION_DEVICE_idx ON DM_DEVICE_LOCATION (DEVICE_ID ASC);
BEGIN BEGIN
EXECUTE IMMEDIATE 'DROP TABLE DM_DEVICE_DETAIL'; EXECUTE IMMEDIATE 'DROP TABLE DM_DEVICE_DETAIL';
EXCEPTION EXCEPTION
WHEN OTHERS THEN NULL; WHEN OTHERS THEN NULL;
END; END;
/ /
@ -793,20 +833,18 @@ CREATE TABLE DM_DEVICE_DETAIL (
UPDATE_TIMESTAMP NUMBER(19) NOT NULL, UPDATE_TIMESTAMP NUMBER(19) NOT NULL,
PRIMARY KEY (ID), PRIMARY KEY (ID),
CONSTRAINT FK_DM_DEVICE_DETAILS_DEVICE CONSTRAINT FK_DM_DEVICE_DETAILS_DEVICE
FOREIGN KEY (DEVICE_ID) FOREIGN KEY (DEVICE_ID)
REFERENCES DM_DEVICE (ID) REFERENCES DM_DEVICE (ID)
); );
-- Generate ID using sequence and trigger -- Generate ID using sequence and trigger
CREATE SEQUENCE DM_DEVICE_DETAIL_seq START WITH 1 INCREMENT BY 1; CREATE SEQUENCE DM_DEVICE_DETAIL_seq START WITH 1 INCREMENT BY 1;
CREATE OR REPLACE TRIGGER DM_DEVICE_DETAIL_seq_tr CREATE OR REPLACE TRIGGER DM_DEVICE_DETAIL_seq_tr
BEFORE INSERT ON DM_DEVICE_DETAIL FOR EACH ROW BEFORE INSERT ON DM_DEVICE_DETAIL FOR EACH ROW
WHEN (NEW.ID IS NULL) WHEN (NEW.ID IS NULL)
BEGIN BEGIN
SELECT DM_DEVICE_DETAIL_seq.NEXTVAL INTO :NEW.ID FROM DUAL; SELECT DM_DEVICE_DETAIL_seq.NEXTVAL INTO :NEW.ID FROM DUAL;
END; END;
/ /
CREATE INDEX FK_DM_DEVICE_DETAILS_DEVICE_idx ON DM_DEVICE_DETAIL (DEVICE_ID ASC);

Loading…
Cancel
Save