diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql index 9b502de09a6..53694c1147f 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql @@ -368,7 +368,7 @@ CREATE TABLE IF NOT EXISTS DM_APPLICATION ( REFERENCES DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION, - CONSTRAINT FK_DM_APP_MAP_DM_ENROL + CONSTRAINT fk_dm_enrolement FOREIGN KEY (ENROLMENT_ID) REFERENCES DM_ENROLMENT (ID) ON DELETE NO ACTION diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql index bf7c12351e5..c1ac997d664 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql @@ -423,26 +423,13 @@ CREATE TABLE DM_APPLICATION ( APP_PROPERTIES VARBINARY(MAX) NULL, MEMORY_USAGE INTEGER NULL, IS_ACTIVE BIT NOT NULL DEFAULT 0, - TENANT_ID INTEGER NOT NULL, - PRIMARY KEY (ID) -); - -IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[DM_DEVICE_APPLICATION_MAPPING]') AND TYPE IN (N'U')) -CREATE TABLE DM_DEVICE_APPLICATION_MAPPING ( - ID INTEGER IDENTITY(1,1) NOT NULL, DEVICE_ID INTEGER NOT NULL, ENROLMENT_ID INTEGER NOT NULL, - APPLICATION_ID INTEGER NOT NULL, - APP_PROPERTIES VARBINARY(MAX) NULL, - MEMORY_USAGE INTEGER NULL, - IS_ACTIVE BIT NOT NULL DEFAULT 0, TENANT_ID INTEGER NOT NULL, PRIMARY KEY (ID), CONSTRAINT FK_DM_DEVICE FOREIGN KEY (DEVICE_ID) REFERENCES DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION, - CONSTRAINT FK_DM_APPLICATION FOREIGN KEY (APPLICATION_ID) REFERENCES - DM_APPLICATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION, - CONSTRAINT FK_DM_APP_MAP_DM_ENROL FOREIGN KEY (ENROLMENT_ID) REFERENCES + CONSTRAINT FK_DM_ENROLMENT FOREIGN KEY (ENROLMENT_ID) REFERENCES DM_ENROLMENT (ID) ON DELETE NO ACTION ON UPDATE NO ACTION ); diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql index c9366d1fe99..d20c9b571d7 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql @@ -402,26 +402,13 @@ CREATE TABLE IF NOT EXISTS DM_APPLICATION ( APP_PROPERTIES BLOB NULL, MEMORY_USAGE INTEGER(10) NULL, IS_ACTIVE BOOLEAN NOT NULL DEFAULT FALSE, - TENANT_ID INTEGER NOT NULL, - PRIMARY KEY (ID) -)ENGINE = InnoDB; - - -CREATE TABLE IF NOT EXISTS DM_DEVICE_APPLICATION_MAPPING ( - ID INTEGER AUTO_INCREMENT NOT NULL, DEVICE_ID INTEGER NOT NULL, ENROLMENT_ID INTEGER NOT NULL, - APPLICATION_ID INTEGER NOT NULL, - APP_PROPERTIES BLOB NULL, - MEMORY_USAGE INTEGER(10) NULL, - IS_ACTIVE BOOLEAN NOT NULL DEFAULT FALSE, TENANT_ID INTEGER NOT NULL, PRIMARY KEY (ID), CONSTRAINT fk_dm_device FOREIGN KEY (DEVICE_ID) REFERENCES DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION, - CONSTRAINT fk_dm_application FOREIGN KEY (APPLICATION_ID) REFERENCES - DM_APPLICATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION, - CONSTRAINT FK_DM_APP_MAP_DM_ENROL FOREIGN KEY (ENROLMENT_ID) REFERENCES + CONSTRAINT fk_dm_enrolement FOREIGN KEY (ENROLMENT_ID) REFERENCES DM_ENROLMENT (ID) ON DELETE NO ACTION ON UPDATE NO ACTION )ENGINE = InnoDB; diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/oracle.sql b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/oracle.sql index ce735f70e94..7631c201d0e 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/oracle.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/oracle.sql @@ -737,54 +737,27 @@ CREATE TABLE DM_APPLICATION ( APP_PROPERTIES BLOB NULL, MEMORY_USAGE NUMBER(10) NULL, IS_ACTIVE NUMBER(10) DEFAULT 0 NOT NULL, - TENANT_ID NUMBER(10) NOT NULL, - CONSTRAINT PK_DM_APPLICATION PRIMARY KEY (ID) -) -/ --- Generate ID using sequence and trigger -CREATE SEQUENCE DM_APPLICATION_seq START WITH 1 INCREMENT BY 1 NOCACHE -/ -CREATE OR REPLACE TRIGGER DM_APPLICATION_seq_tr -BEFORE INSERT -ON DM_APPLICATION -REFERENCING NEW AS NEW -FOR EACH ROW -WHEN (NEW.ID IS NULL) - BEGIN - SELECT DM_APPLICATION_seq.NEXTVAL INTO :NEW.ID FROM DUAL; - END; -/ - - -CREATE TABLE DM_DEVICE_APPLICATION_MAPPING ( - ID NUMBER(10) NOT NULL, DEVICE_ID NUMBER(10) NOT NULL, ENROLMENT_ID NUMBER(10 NOT NULL, - APPLICATION_ID NUMBER(10) NOT NULL, - APP_PROPERTIES BLOB NULL, - MEMORY_USAGE NUMBER(10) NULL, - IS_ACTIVE NUMBER(10) DEFAULT 0 NOT NULL, TENANT_ID NUMBER(10) NOT NULL, - CONSTRAINT PK_DM_DEVICE_APP_MAPPING PRIMARY KEY (ID), + CONSTRAINT PK_DM_APPLICATION PRIMARY KEY (ID), CONSTRAINT fk_dm_device FOREIGN KEY (DEVICE_ID) REFERENCES DM_DEVICE (ID), - CONSTRAINT fk_dm_application FOREIGN KEY (APPLICATION_ID) REFERENCES - DM_APPLICATION (ID), - CONSTRAINT FK_DM_APP_MAP_DM_ENROL FOREIGN KEY (ENROLMENT_ID) REFERENCES + CONSTRAINT fk_dm_enrolment FOREIGN KEY (ENROLMENT_ID) REFERENCES DM_ENROLMENT (ID) ) / -- Generate ID using sequence and trigger -CREATE SEQUENCE DM_DEVICE_APP_MAPPING_seq START WITH 1 INCREMENT BY 1 NOCACHE +CREATE SEQUENCE DM_APPLICATION_seq START WITH 1 INCREMENT BY 1 NOCACHE / -CREATE OR REPLACE TRIGGER DM_DEVICE_APP_MAPPING_seq_tr +CREATE OR REPLACE TRIGGER DM_APPLICATION_seq_tr BEFORE INSERT -ON DM_DEVICE_APPLICATION_MAPPING +ON DM_APPLICATION REFERENCING NEW AS NEW FOR EACH ROW WHEN (NEW.ID IS NULL) BEGIN - SELECT DM_DEVICE_APP_MAPPING_seq.NEXTVAL INTO :NEW.ID FROM DUAL; + SELECT DM_APPLICATION_seq.NEXTVAL INTO :NEW.ID FROM DUAL; END; / diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/postgresql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/postgresql.sql index c527642e8c8..f12d0be98c9 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/postgresql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/postgresql.sql @@ -381,23 +381,12 @@ CREATE TABLE IF NOT EXISTS DM_APPLICATION ( APP_PROPERTIES BYTEA NULL, MEMORY_USAGE INTEGER NULL, IS_ACTIVE BOOLEAN NOT NULL DEFAULT FALSE, - TENANT_ID INTEGER NOT NULL -); - -CREATE TABLE IF NOT EXISTS DM_DEVICE_APPLICATION_MAPPING ( - ID BIGSERIAL NOT NULL PRIMARY KEY, - DEVICE_ID INTEGER NOT NULL, - ENROLMENT_ID INTEGER NOT NULL, - APPLICATION_ID INTEGER NOT NULL, - APP_PROPERTIES BYTEA NULL, - MEMORY_USAGE INTEGER NULL, - IS_ACTIVE BOOLEAN NOT NULL DEFAULT FALSE, - TENANT_ID INTEGER NOT NULL, + DEVICE_ID INTEGER NOT NULL, + ENROLMENT_ID INTEGER NOT NULL, + TENANT_ID INTEGER NOT NULL, CONSTRAINT fk_dm_device FOREIGN KEY (DEVICE_ID) REFERENCES DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION, - CONSTRAINT fk_dm_application FOREIGN KEY (APPLICATION_ID) REFERENCES - DM_APPLICATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION, - CONSTRAINT FK_DM_APP_MAP_DM_ENROL FOREIGN KEY (ENROLMENT_ID) REFERENCES + CONSTRAINT fk_dm_enrollement FOREIGN KEY (ENROLMENT_ID) REFERENCES DM_ENROLMENT (ID) ON DELETE NO ACTION ON UPDATE NO ACTION );