Merge pull request 'Fix MSSQL dbscripts of DM_DB, APPM_DB' (#66) from prathabanKavin/device-mgt-core:mssqlfix into master

Reviewed-on: community/device-mgt-core#66
improvement/fix-task-deletion
Inosh Perara 2 years ago
commit 0a9661f98e

@ -1,6 +1,7 @@
-- -----------------------------------------------------
-- Table AP_APP
-- -----------------------------------------------------
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AP_APP]') AND TYPE IN (N'U'))
CREATE TABLE AP_APP(
ID INTEGER NOT NULL IDENTITY,
NAME VARCHAR(350) NOT NULL,
@ -18,6 +19,7 @@ CREATE TABLE AP_APP(
-- -----------------------------------------------------
-- Table AP_APP_RELEASE
-- -----------------------------------------------------
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AP_APP_RELEASE]') AND TYPE IN (N'U'))
CREATE TABLE AP_APP_RELEASE(
ID INTEGER NOT NULL IDENTITY,
DESCRIPTION VARCHAR(max) NOT NULL,
@ -52,6 +54,7 @@ CREATE INDEX fk_AP_APP_RELEASE_AP_APP1_idx ON AP_APP_RELEASE (AP_APP_ID ASC);
-- -----------------------------------------------------
-- Table AP_APP_REVIEW
-- -----------------------------------------------------
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AP_APP_REVIEW]') AND TYPE IN (N'U'))
CREATE TABLE AP_APP_REVIEW(
ID INTEGER NOT NULL IDENTITY,
TENANT_ID INTEGER NOT NULL,
@ -74,6 +77,7 @@ CREATE INDEX fk_AP_APP_COMMENT_AP_APP_RELEASE1_idx ON AP_APP_REVIEW (AP_APP_RELE
-- -----------------------------------------------------
-- Table AP_APP_LIFECYCLE_STATE
-- -----------------------------------------------------
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AP_APP_LIFECYCLE_STATE]') AND TYPE IN (N'U'))
CREATE TABLE AP_APP_LIFECYCLE_STATE(
ID INTEGER NOT NULL IDENTITY,
CURRENT_STATE VARCHAR(45) NOT NULL,
@ -93,6 +97,7 @@ CREATE INDEX fk_AP_APP_LIFECYCLE_STATE_AP_APP_RELEASE1_idx ON AP_APP_LIFECYCLE_S
-- -----------------------------------------------------
-- Table AP_APP_TAG
-- -----------------------------------------------------
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AP_APP_TAG]') AND TYPE IN (N'U'))
CREATE TABLE AP_APP_TAG(
ID INTEGER NOT NULL IDENTITY,
TENANT_ID INTEGER NOT NULL,
@ -103,6 +108,7 @@ CREATE TABLE AP_APP_TAG(
-- -----------------------------------------------------
-- Table AP_DEVICE_SUBSCRIPTION
-- -----------------------------------------------------
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AP_DEVICE_SUBSCRIPTION]') AND TYPE IN (N'U'))
CREATE TABLE AP_DEVICE_SUBSCRIPTION(
ID INTEGER NOT NULL IDENTITY,
TENANT_ID INTEGER NOT NULL,
@ -126,6 +132,7 @@ CREATE INDEX fk_AP_DEVICE_SUBSCRIPTION_AP_APP_RELEASE1_idx ON AP_DEVICE_SUBSCRIP
-- -----------------------------------------------------
-- Table AP_GROUP_SUBSCRIPTION
-- -----------------------------------------------------
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AP_GROUP_SUBSCRIPTION]') AND TYPE IN (N'U'))
CREATE TABLE AP_GROUP_SUBSCRIPTION(
ID INTEGER NOT NULL IDENTITY,
TENANT_ID INTEGER NOT NULL,
@ -146,6 +153,7 @@ CREATE INDEX fk_AP_GROUP_SUBSCRIPTION_AP_APP_RELEASE1_idx ON AP_GROUP_SUBSCRIPTI
-- -----------------------------------------------------
-- Table AP_ROLE_SUBSCRIPTION
-- -----------------------------------------------------
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AP_ROLE_SUBSCRIPTION]') AND TYPE IN (N'U'))
CREATE TABLE AP_ROLE_SUBSCRIPTION(
ID INTEGER NOT NULL IDENTITY,
TENANT_ID INTEGER NOT NULL,
@ -166,6 +174,7 @@ CREATE INDEX fk_AP_ROLE_SUBSCRIPTION_AP_APP_RELEASE1_idx ON AP_ROLE_SUBSCRIPTION
-- -----------------------------------------------------
-- Table AP_UNRESTRICTED_ROLE
-- -----------------------------------------------------
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AP_UNRESTRICTED_ROLE]') AND TYPE IN (N'U'))
CREATE TABLE AP_UNRESTRICTED_ROLE(
ID INTEGER NOT NULL IDENTITY,
TENANT_ID INTEGER NOT NULL,
@ -181,6 +190,7 @@ CREATE INDEX fk_AP_APP_VISIBILITY_AP_APP1_idx ON AP_UNRESTRICTED_ROLE (AP_APP_ID
-- -----------------------------------------------------
-- Table AP_USER_SUBSCRIPTION
-- -----------------------------------------------------
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AP_USER_SUBSCRIPTION]') AND TYPE IN (N'U'))
CREATE TABLE AP_USER_SUBSCRIPTION(
ID INTEGER NOT NULL IDENTITY,
TENANT_ID INTEGER NOT NULL,
@ -201,6 +211,7 @@ CREATE INDEX fk_AP_USER_SUBSCRIPTION_AP_APP_RELEASE1_idx ON AP_USER_SUBSCRIPTION
-- -----------------------------------------------------
-- Table AP_APP_CATEGORY
-- -----------------------------------------------------
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AP_APP_CATEGORY]') AND TYPE IN (N'U'))
CREATE TABLE AP_APP_CATEGORY(
ID INTEGER NOT NULL IDENTITY,
TENANT_ID INTEGER NOT NULL,
@ -212,6 +223,7 @@ CREATE TABLE AP_APP_CATEGORY(
-- -----------------------------------------------------
-- Table AP_APP_TAG_MAPPING
-- -----------------------------------------------------
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AP_APP_TAG_MAPPING]') AND TYPE IN (N'U'))
CREATE TABLE AP_APP_TAG_MAPPING(
ID INTEGER NOT NULL IDENTITY,
TENANT_ID INTEGER NOT NULL,
@ -231,6 +243,7 @@ CREATE INDEX fk_AP_APP_TAG_copy1_AP_APP1_idx ON AP_APP_TAG_MAPPING (AP_APP_ID AS
-- -----------------------------------------------------
-- Table AP_APP_CATEGORY_MAPPING
-- -----------------------------------------------------
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AP_APP_CATEGORY_MAPPING]') AND TYPE IN (N'U'))
CREATE TABLE AP_APP_CATEGORY_MAPPING(
ID INTEGER NOT NULL IDENTITY,
TENANT_ID INTEGER NOT NULL,
@ -250,6 +263,7 @@ CREATE INDEX fk_AP_APP_CATEGORY_copy1_AP_APP1_idx ON AP_APP_CATEGORY_MAPPING (AP
-- -----------------------------------------------------
-- Table AP_APP_SUB_OP_MAPPING
-- -----------------------------------------------------
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AP_APP_SUB_OP_MAPPING]') AND TYPE IN (N'U'))
CREATE TABLE AP_APP_SUB_OP_MAPPING (
ID INTEGER NOT NULL IDENTITY,
TENANT_ID INTEGER NOT NULL,
@ -265,6 +279,7 @@ CREATE INDEX fk_AP_APP_SUB_OP_MAPPING_AP_DEVICE_SUBSCRIPTION1_idx ON AP_APP_SUB_
-- -----------------------------------------------------
-- Table AP_SCHEDULED_SUBSCRIPTION
-- -----------------------------------------------------
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AP_SCHEDULED_SUBSCRIPTION]') AND TYPE IN (N'U'))
CREATE TABLE AP_SCHEDULED_SUBSCRIPTION(
ID INTEGER NOT NULL IDENTITY,
TASK_NAME VARCHAR(100) NOT NULL,
@ -284,7 +299,8 @@ CREATE TABLE AP_SCHEDULED_SUBSCRIPTION(
-- -----------------------------------------------------
-- Table AP_IDENTITY_SERVER
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS AP_IDENTITY_SERVER (
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AP_IDENTITY_SERVER]') AND TYPE IN (N'U'))
CREATE TABLE AP_IDENTITY_SERVER (
ID INTEGER NOT NULL IDENTITY,
NAME VARCHAR(255) NOT NULL,
PROVIDER_NAME VARCHAR(255) NOT NULL,
@ -299,8 +315,9 @@ CREATE TABLE IF NOT EXISTS AP_IDENTITY_SERVER (
-- -----------------------------------------------------
-- Table AP_IS_SP_APP_MAPPING
-- -----------------------------------------------------;
CREATE TABLE IF NOT EXISTS AP_IS_SP_APP_MAPPING (
-- -----------------------------------------------------
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AP_IS_SP_APP_MAPPING]') AND TYPE IN (N'U'))
CREATE TABLE AP_IS_SP_APP_MAPPING (
ID INTEGER NOT NULL IDENTITY,
SP_UID VARCHAR(255) NOT NULL,
AP_APP_ID INT NOT NULL,
@ -314,7 +331,8 @@ CREATE TABLE IF NOT EXISTS AP_IS_SP_APP_MAPPING (
-- -----------------------------------------------------
-- Table AP_APP_FAVOURITES
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS AP_APP_FAVOURITES(
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AP_APP_FAVOURITES]') AND TYPE IN (N'U'))
CREATE TABLE AP_APP_FAVOURITES(
ID INTEGER NOT NULL IDENTITY,
AP_APP_ID INTEGER NOT NULL,
USER_NAME VARCHAR(100) NOT NULL,

@ -120,21 +120,6 @@ CREATE TABLE DM_OPERATION (
PRIMARY KEY (ID)
);
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[DM_DEVICE_STATUS]') AND TYPE IN (N'U'))
CREATE TABLE DM_DEVICE_STATUS (
ID INTEGER IDENTITY(1,1) NOT NULL,
ENROLMENT_ID INTEGER NOT NULL,
DEVICE_ID INTEGER NOT NULL,
STATUS VARCHAR(50) DEFAULT NULL,
UPDATE_TIME DATETIME2 DEFAULT NULL,
CHANGED_BY VARCHAR(255) NOT NULL,
PRIMARY KEY (ID),
CONSTRAINT FK_DM_DEVICE_STATUS_DEVICE FOREIGN KEY (DEVICE_ID) REFERENCES
DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT FK_DM_DEVICE_STATUS_ENROLMENT FOREIGN KEY (ENROLMENT_ID) REFERENCES
DM_ENROLMENT (ID) ON DELETE CASCADE ON UPDATE CASCADE
);
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[DM_ENROLMENT]') AND TYPE IN (N'U'))
CREATE TABLE DM_ENROLMENT (
ID INTEGER IDENTITY(1,1) NOT NULL,
@ -151,6 +136,21 @@ CREATE TABLE DM_ENROLMENT (
DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
);
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[DM_DEVICE_STATUS]') AND TYPE IN (N'U'))
CREATE TABLE DM_DEVICE_STATUS (
ID INTEGER IDENTITY(1,1) NOT NULL,
ENROLMENT_ID INTEGER NOT NULL,
DEVICE_ID INTEGER NOT NULL,
STATUS VARCHAR(50) DEFAULT NULL,
UPDATE_TIME DATETIME2 DEFAULT NULL,
CHANGED_BY VARCHAR(255) NOT NULL,
PRIMARY KEY (ID),
CONSTRAINT FK_DM_DEVICE_STATUS_DEVICE FOREIGN KEY (DEVICE_ID) REFERENCES
DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT FK_DM_DEVICE_STATUS_ENROLMENT FOREIGN KEY (ENROLMENT_ID) REFERENCES
DM_ENROLMENT (ID) ON DELETE CASCADE ON UPDATE CASCADE
);
IF NOT EXISTS (SELECT * FROM SYS.INDEXES WHERE NAME = 'IDX_ENROLMENT_FK_DEVICE_ID' AND OBJECT_ID = OBJECT_ID('DM_ENROLMENT'))
CREATE INDEX IDX_ENROLMENT_FK_DEVICE_ID ON DM_ENROLMENT(DEVICE_ID);
IF NOT EXISTS (SELECT * FROM SYS.INDEXES WHERE NAME = 'IDX_ENROLMENT_DEVICE_ID_TENANT_ID' AND OBJECT_ID = OBJECT_ID('DM_ENROLMENT'))
@ -639,10 +639,10 @@ CREATE TABLE DM_OTP_DATA (
USERNAME VARCHAR(500) NOT NULL,
EMAIL VARCHAR(100) NOT NULL,
EMAIL_TYPE VARCHAR(20) NOT NULL,
META_INFO VARCHAR(20000) NOT NULL,
META_INFO VARCHAR(8000) NOT NULL,
CREATED_AT DATETIME2(0) NOT NULL,
EXPIRY_TIME INT NOT NULL DEFAULT 3600,
IS_EXPIRED BIT DEFAULT false,
IS_EXPIRED BIT DEFAULT 0,
PRIMARY KEY (ID),
CONSTRAINT email_type_uk UNIQUE (EMAIL, EMAIL_TYPE)
);
@ -718,8 +718,8 @@ CREATE TABLE DM_GEOFENCE (
ID INT IDENTITY NOT NULL,
FENCE_NAME VARCHAR(255) NOT NULL,
DESCRIPTION VARCHAR(MAX) DEFAULT NULL,
LATITUDE DECIMAL(3,5) DEFAULT NULL,
LONGITUDE DECIMAL(3,5) DEFAULT NULL,
LATITUDE FLOAT DEFAULT NULL,
LONGITUDE FLOAT DEFAULT NULL,
RADIUS DECIMAL(30,4) DEFAULT NULL,
GEO_JSON VARCHAR(MAX) DEFAULT NULL,
FENCE_SHAPE VARCHAR(100) DEFAULT NULL,
@ -733,18 +733,18 @@ CREATE TABLE DM_GEOFENCE (
-- DYNAMIC TASK TABLES--
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[DYNAMIC_TASK]') AND TYPE IN (N'U'))
CREATE TABLE IF NOT EXISTS DYNAMIC_TASK (
CREATE TABLE DYNAMIC_TASK (
DYNAMIC_TASK_ID INTEGER IDENTITY(1,1) NOT NULL,
NAME VARCHAR(255) DEFAULT NULL ,
CRON VARCHAR(8000) DEFAULT NULL,
IS_ENABLED BOOLEAN NOT NULL DEFAULT FALSE,
IS_ENABLED BIT NOT NULL DEFAULT 0,
TASK_CLASS_NAME VARCHAR(8000) DEFAULT NULL,
TENANT_ID INTEGER DEFAULT 0,
PRIMARY KEY (DYNAMIC_TASK_ID)
);
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[DYNAMIC_TASK_PROPERTIES]')
AND TYPE IN (N'U'))
CREATE TABLE IF NOT EXISTS DYNAMIC_TASK_PROPERTIES (
IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[DYNAMIC_TASK_PROPERTIES]') AND TYPE IN (N'U'))
CREATE TABLE DYNAMIC_TASK_PROPERTIES (
DYNAMIC_TASK_ID INTEGER NOT NULL,
PROPERTY_NAME VARCHAR(100) DEFAULT 0,
PROPERTY_VALUE VARCHAR(100) DEFAULT NULL,

Loading…
Cancel
Save