Fix SQL error in Application Management

4.x.x
Charitha Goonetilleke 5 years ago
parent 91e39d0b04
commit 22d542ed96

@ -368,7 +368,7 @@ CREATE TABLE IF NOT EXISTS DM_APPLICATION (
REFERENCES DM_DEVICE (ID) REFERENCES DM_DEVICE (ID)
ON DELETE NO ACTION ON DELETE NO ACTION
ON UPDATE NO ACTION, ON UPDATE NO ACTION,
CONSTRAINT FK_DM_APP_MAP_DM_ENROL CONSTRAINT fk_dm_enrolement
FOREIGN KEY (ENROLMENT_ID) FOREIGN KEY (ENROLMENT_ID)
REFERENCES DM_ENROLMENT (ID) REFERENCES DM_ENROLMENT (ID)
ON DELETE NO ACTION ON DELETE NO ACTION

@ -423,26 +423,13 @@ CREATE TABLE DM_APPLICATION (
APP_PROPERTIES VARBINARY(MAX) NULL, APP_PROPERTIES VARBINARY(MAX) NULL,
MEMORY_USAGE INTEGER NULL, MEMORY_USAGE INTEGER NULL,
IS_ACTIVE BIT NOT NULL DEFAULT 0, 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, DEVICE_ID INTEGER NOT NULL,
ENROLMENT_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, TENANT_ID INTEGER NOT NULL,
PRIMARY KEY (ID), PRIMARY KEY (ID),
CONSTRAINT FK_DM_DEVICE FOREIGN KEY (DEVICE_ID) REFERENCES CONSTRAINT FK_DM_DEVICE FOREIGN KEY (DEVICE_ID) REFERENCES
DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION, DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT FK_DM_APPLICATION FOREIGN KEY (APPLICATION_ID) REFERENCES CONSTRAINT FK_DM_ENROLMENT FOREIGN KEY (ENROLMENT_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
DM_ENROLMENT (ID) ON DELETE NO ACTION ON UPDATE NO ACTION DM_ENROLMENT (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
); );

@ -402,26 +402,13 @@ CREATE TABLE IF NOT EXISTS DM_APPLICATION (
APP_PROPERTIES BLOB NULL, APP_PROPERTIES BLOB NULL,
MEMORY_USAGE INTEGER(10) NULL, MEMORY_USAGE INTEGER(10) NULL,
IS_ACTIVE BOOLEAN NOT NULL DEFAULT FALSE, 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, DEVICE_ID INTEGER NOT NULL,
ENROLMENT_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, TENANT_ID INTEGER NOT NULL,
PRIMARY KEY (ID), PRIMARY KEY (ID),
CONSTRAINT fk_dm_device FOREIGN KEY (DEVICE_ID) REFERENCES CONSTRAINT fk_dm_device FOREIGN KEY (DEVICE_ID) REFERENCES
DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION, DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT fk_dm_application FOREIGN KEY (APPLICATION_ID) REFERENCES CONSTRAINT fk_dm_enrolement FOREIGN KEY (ENROLMENT_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
DM_ENROLMENT (ID) ON DELETE NO ACTION ON UPDATE NO ACTION DM_ENROLMENT (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
)ENGINE = InnoDB; )ENGINE = InnoDB;

@ -737,54 +737,27 @@ CREATE TABLE DM_APPLICATION (
APP_PROPERTIES BLOB NULL, APP_PROPERTIES BLOB NULL,
MEMORY_USAGE NUMBER(10) NULL, MEMORY_USAGE NUMBER(10) NULL,
IS_ACTIVE NUMBER(10) DEFAULT 0 NOT 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, DEVICE_ID NUMBER(10) NOT NULL,
ENROLMENT_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, 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 CONSTRAINT fk_dm_device FOREIGN KEY (DEVICE_ID) REFERENCES
DM_DEVICE (ID), DM_DEVICE (ID),
CONSTRAINT fk_dm_application FOREIGN KEY (APPLICATION_ID) REFERENCES CONSTRAINT fk_dm_enrolment FOREIGN KEY (ENROLMENT_ID) REFERENCES
DM_APPLICATION (ID),
CONSTRAINT FK_DM_APP_MAP_DM_ENROL FOREIGN KEY (ENROLMENT_ID) REFERENCES
DM_ENROLMENT (ID) DM_ENROLMENT (ID)
) )
/ /
-- Generate ID using sequence and trigger -- 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 BEFORE INSERT
ON DM_DEVICE_APPLICATION_MAPPING ON DM_APPLICATION
REFERENCING NEW AS NEW REFERENCING NEW AS NEW
FOR EACH ROW FOR EACH ROW
WHEN (NEW.ID IS NULL) WHEN (NEW.ID IS NULL)
BEGIN BEGIN
SELECT DM_DEVICE_APP_MAPPING_seq.NEXTVAL INTO :NEW.ID FROM DUAL; SELECT DM_APPLICATION_seq.NEXTVAL INTO :NEW.ID FROM DUAL;
END; END;
/ /

@ -381,23 +381,12 @@ CREATE TABLE IF NOT EXISTS DM_APPLICATION (
APP_PROPERTIES BYTEA NULL, APP_PROPERTIES BYTEA NULL,
MEMORY_USAGE INTEGER NULL, MEMORY_USAGE INTEGER NULL,
IS_ACTIVE BOOLEAN NOT NULL DEFAULT FALSE, 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, DEVICE_ID INTEGER NOT NULL,
ENROLMENT_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, TENANT_ID INTEGER NOT NULL,
CONSTRAINT fk_dm_device FOREIGN KEY (DEVICE_ID) REFERENCES CONSTRAINT fk_dm_device FOREIGN KEY (DEVICE_ID) REFERENCES
DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION, DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT fk_dm_application FOREIGN KEY (APPLICATION_ID) REFERENCES CONSTRAINT fk_dm_enrollement FOREIGN KEY (ENROLMENT_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
DM_ENROLMENT (ID) ON DELETE NO ACTION ON UPDATE NO ACTION DM_ENROLMENT (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
); );

Loading…
Cancel
Save