Fixed issues in Oracle DB script

revert-70aa11f8
Dileesha Rajapakse 9 years ago
parent 2a9e2a47e8
commit cb5736854a

@ -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,
@ -588,11 +636,11 @@ CREATE TABLE DM_DEVICE_GROUP_POLICY (
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;
/ /
@ -691,7 +739,7 @@ WHEN (NEW.NOTIFICATION_ID IS NULL)
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;
/ /
@ -713,20 +761,16 @@ 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;
/ /
@ -755,20 +799,16 @@ 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;
/ /
@ -801,12 +841,10 @@ CREATE TABLE DM_DEVICE_DETAIL (
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