Refactored oracle DB script

revert-70aa11f8
Dileesha Rajapakse 9 years ago
parent 473c06f347
commit fca2e515b0

@ -26,7 +26,7 @@ CREATE TABLE DM_DEVICE (
DEVICE_IDENTIFICATION VARCHAR2(300) DEFAULT NULL,
TENANT_ID NUMBER(10) DEFAULT 0,
CONSTRAINT PK_DM_DEVICE PRIMARY KEY (ID),
CONSTRAINT fk_DM_DEVICE_DM_DEVICE_TYPE2 FOREIGN KEY (DEVICE_TYPE_ID )
CONSTRAINT FK_DM_DEVICE_DM_DEVICE_TYPE2 FOREIGN KEY (DEVICE_TYPE_ID )
REFERENCES DM_DEVICE_TYPE (ID)
)
/
@ -71,7 +71,7 @@ CREATE TABLE DM_CONFIG_OPERATION (
OPERATION_ID NUMBER(10) NOT NULL,
OPERATION_CONFIG BLOB DEFAULT NULL,
CONSTRAINT PK_DM_CONFIG_OPERATION PRIMARY KEY (OPERATION_ID),
CONSTRAINT fk_dm_operation_config FOREIGN KEY (OPERATION_ID) REFERENCES
CONSTRAINT FK_DM_OPERATION_CONFIG FOREIGN KEY (OPERATION_ID) REFERENCES
DM_OPERATION (ID)
)
/
@ -79,7 +79,7 @@ CREATE TABLE DM_COMMAND_OPERATION (
OPERATION_ID NUMBER(10) NOT NULL,
ENABLED NUMBER(10) DEFAULT 0 NOT NULL,
CONSTRAINT PK_DM_COMMAND_OPERATION PRIMARY KEY (OPERATION_ID),
CONSTRAINT fk_dm_operation_command FOREIGN KEY (OPERATION_ID) REFERENCES
CONSTRAINT FK_DM_OPERATION_COMMAND FOREIGN KEY (OPERATION_ID) REFERENCES
DM_OPERATION (ID)
)
/
@ -88,7 +88,7 @@ CREATE TABLE DM_POLICY_OPERATION (
ENABLED NUMBER(10) DEFAULT 0 NOT NULL,
OPERATION_DETAILS BLOB DEFAULT NULL,
CONSTRAINT PK_DM_POLICY_OPERATION PRIMARY KEY (OPERATION_ID),
CONSTRAINT fk_dm_operation_policy FOREIGN KEY (OPERATION_ID) REFERENCES
CONSTRAINT FK_DM_OPERATION_POLICY FOREIGN KEY (OPERATION_ID) REFERENCES
DM_OPERATION (ID)
)
/
@ -97,7 +97,7 @@ CREATE TABLE DM_PROFILE_OPERATION (
ENABLED NUMBER(10) DEFAULT 0 NOT NULL,
OPERATION_DETAILS BLOB DEFAULT NULL,
CONSTRAINT PK_DM_PROFILE_OPERATION PRIMARY KEY (OPERATION_ID),
CONSTRAINT fk_dm_operation_profile FOREIGN KEY (OPERATION_ID) REFERENCES
CONSTRAINT FK_DM_OPERATION_PROFILE FOREIGN KEY (OPERATION_ID) REFERENCES
DM_OPERATION (ID)
)
/
@ -111,7 +111,7 @@ CREATE TABLE DM_ENROLMENT (
DATE_OF_LAST_UPDATE TIMESTAMP(0) DEFAULT NULL,
TENANT_ID NUMBER(10) NOT NULL,
CONSTRAINT PK_DM_ENROLMENT PRIMARY KEY (ID),
CONSTRAINT fk_dm_device_enrolment FOREIGN KEY (DEVICE_ID) REFERENCES
CONSTRAINT FK_DM_DEVICE_ENROLMENT FOREIGN KEY (DEVICE_ID) REFERENCES
DM_DEVICE (ID)
)
/
@ -129,29 +129,29 @@ WHEN (NEW.ID IS NULL)
END;
/
CREATE TABLE DM_ENROLMENT_op_map (
CREATE TABLE DM_ENROLMENT_OP_MAP (
ID NUMBER(10) NOT NULL,
ENROLMENT_ID NUMBER(10) NOT NULL,
OPERATION_ID NUMBER(10) NOT NULL,
STATUS VARCHAR2(50) NULL,
PRIMARY KEY (ID),
CONSTRAINT fk_dm_device_op_map_device FOREIGN KEY (ENROLMENT_ID) REFERENCES
CONSTRAINT FK_DM_DEVICE_OP_MAP_DEVICE FOREIGN KEY (ENROLMENT_ID) REFERENCES
DM_ENROLMENT (ID),
CONSTRAINT fk_dm_device_op_map_operation FOREIGN KEY (OPERATION_ID) REFERENCES
CONSTRAINT FK_DM_DEVICE_OP_MAP_OPERATION FOREIGN KEY (OPERATION_ID) REFERENCES
DM_OPERATION (ID)
)
/
-- Generate ID using sequence and trigger
CREATE SEQUENCE DM_ENROLMENT_op_map_seq START WITH 1 INCREMENT BY 1 NOCACHE
CREATE SEQUENCE DM_ENROLMENT_OP_MAP_seq START WITH 1 INCREMENT BY 1 NOCACHE
/
CREATE OR REPLACE TRIGGER DM_ENROLMENT_op_map_seq_tr
CREATE OR REPLACE TRIGGER DM_ENROLMENT_OP_MAP_seq_tr
BEFORE INSERT
ON DM_ENROLMENT_op_map
REFERENCING NEW AS NEW
FOR EACH ROW
WHEN (NEW.ID IS NULL)
BEGIN
SELECT DM_ENROLMENT_op_map_seq.NEXTVAL INTO :NEW.ID FROM DUAL;
SELECT DM_ENROLMENT_OP_MAP_seq.NEXTVAL INTO :NEW.ID FROM DUAL;
END;
/
@ -161,9 +161,9 @@ CREATE TABLE DM_DEVICE_OPERATION_RESPONSE (
OPERATION_ID NUMBER(10) NOT NULL,
OPERATION_RESPONSE BLOB DEFAULT NULL,
CONSTRAINT PK_DM_DEVICE_OP_RESPONSE PRIMARY KEY (ID),
CONSTRAINT fk_dm_device_op_res_device FOREIGN KEY (DEVICE_ID) REFERENCES
CONSTRAINT FK_DM_DEVICE_OP_RES_DEVICE FOREIGN KEY (DEVICE_ID) REFERENCES
DM_DEVICE (ID),
CONSTRAINT fk_dm_device_op_res_operation FOREIGN KEY (OPERATION_ID) REFERENCES
CONSTRAINT FK_DM_DEVICE_OP_RES_OPERATION FOREIGN KEY (OPERATION_ID) REFERENCES
DM_OPERATION (ID)
)
/
@ -621,9 +621,9 @@ CREATE TABLE DM_NOTIFICATION (
STATUS VARCHAR2(10) NULL,
DESCRIPTION VARCHAR2(100) NULL,
CONSTRAINT PK_DM_NOTIFICATION PRIMARY KEY (NOTIFICATION_ID),
CONSTRAINT fk_dm_device_notification FOREIGN KEY (DEVICE_ID) REFERENCES
CONSTRAINT FK_DM_DEVICE_NOTIFICATION FOREIGN KEY (DEVICE_ID) REFERENCES
DM_DEVICE (ID),
CONSTRAINT fk_dm_operation_notification FOREIGN KEY (OPERATION_ID) REFERENCES
CONSTRAINT FK_DM_OPERATION_NOTIFICATION FOREIGN KEY (OPERATION_ID) REFERENCES
DM_OPERATION (ID)
)
/

Loading…
Cancel
Save