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,
@ -720,10 +768,6 @@ BEGIN
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
@ -762,10 +806,6 @@ BEGIN
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
@ -808,5 +848,3 @@ BEGIN
END; END;
/ /
CREATE INDEX FK_DM_DEVICE_DETAILS_DEVICE_idx ON DM_DEVICE_DETAIL (DEVICE_ID ASC);

Loading…
Cancel
Save