Fixed errors in MSSQL DB script

merge-requests/7/head
Dileesha Rajapakse 9 years ago
parent cb5736854a
commit e055519d4c

@ -2,7 +2,18 @@ CREATE TABLE DM_DEVICE_TYPE (
ID INTEGER IDENTITY NOT NULL,
NAME VARCHAR(300) DEFAULT NULL,
PROVIDER_TENANT_ID INTEGER DEFAULT 0,
SHARED_WITH_ALL_TENANTS BOOLEAN NOT NULL DEFAULT FALSE,
SHARED_WITH_ALL_TENANTS INTEGER NOT NULL DEFAULT 0,
PRIMARY KEY (ID)
);
CREATE TABLE DM_GROUP (
ID INTEGER IDENTITY NOT NULL,
GROUP_NAME VARCHAR(100) DEFAULT NULL,
DESCRIPTION VARCHAR(max) DEFAULT NULL,
DATE_OF_CREATE BIGINT DEFAULT NULL,
DATE_OF_LAST_UPDATE BIGINT DEFAULT NULL,
OWNER VARCHAR(45) DEFAULT NULL,
TENANT_ID INTEGER DEFAULT 0,
PRIMARY KEY (ID)
);
@ -18,7 +29,7 @@ CREATE TABLE DM_DEVICE (
ID INTEGER identity NOT NULL,
DESCRIPTION VARCHAR(max) DEFAULT NULL,
NAME VARCHAR(100) DEFAULT NULL,
DEVICE_TYPE_ID INT DEFAULT NULL,
DEVICE_TYPE_ID INTEGER DEFAULT NULL,
DEVICE_IDENTIFICATION VARCHAR(300) DEFAULT NULL,
TENANT_ID INTEGER DEFAULT 0,
PRIMARY KEY (ID),
@ -26,6 +37,18 @@ CREATE TABLE DM_DEVICE (
REFERENCES DM_DEVICE_TYPE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
);
CREATE TABLE DM_DEVICE_GROUP_MAP (
ID INTEGER IDENTITY NOT NULL,
DEVICE_ID INTEGER DEFAULT NULL,
GROUP_ID INTEGER DEFAULT NULL,
TENANT_ID INTEGER DEFAULT 0,
PRIMARY KEY (ID),
CONSTRAINT fk_DM_DEVICE_GROUP_MAP_DM_DEVICE2 FOREIGN KEY (DEVICE_ID)
REFERENCES DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT fk_DM_DEVICE_GROUP_MAP_DM_GROUP2 FOREIGN KEY (GROUP_ID)
REFERENCES DM_GROUP (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
);
CREATE TABLE DM_OPERATION (
ID INTEGER IDENTITY NOT NULL,
TYPE VARCHAR(50) NOT NULL,
@ -77,7 +100,7 @@ CREATE TABLE DM_ENROLMENT (
STATUS VARCHAR(50) NULL,
DATE_OF_ENROLMENT DATETIME2(0) DEFAULT NULL,
DATE_OF_LAST_UPDATE DATETIME2(0) DEFAULT NULL,
TENANT_ID INT NOT NULL,
TENANT_ID INTEGER NOT NULL,
PRIMARY KEY (ID),
CONSTRAINT fk_dm_device_enrolment FOREIGN KEY (DEVICE_ID) REFERENCES
DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
@ -113,10 +136,10 @@ CREATE TABLE DM_DEVICE_OPERATION_RESPONSE (
CREATE TABLE DM_PROFILE (
ID INT NOT NULL IDENTITY ,
ID INTEGER NOT NULL IDENTITY ,
PROFILE_NAME VARCHAR(45) NOT NULL ,
TENANT_ID INT NOT NULL ,
DEVICE_TYPE_ID INT NOT NULL ,
TENANT_ID INTEGER NOT NULL ,
DEVICE_TYPE_ID INTEGER NOT NULL ,
CREATED_TIME DATETIME2(0) NOT NULL ,
UPDATED_TIME DATETIME2(0) NOT NULL ,
PRIMARY KEY (ID) ,
@ -132,16 +155,16 @@ CREATE TABLE DM_PROFILE (
CREATE TABLE DM_POLICY (
ID INT NOT NULL IDENTITY ,
ID INTEGER NOT NULL IDENTITY ,
NAME VARCHAR(45) DEFAULT NULL ,
DESCRIPTION VARCHAR(1000) NULL,
TENANT_ID INT NOT NULL ,
PROFILE_ID INT NOT NULL ,
TENANT_ID INTEGER NOT NULL ,
PROFILE_ID INTEGER NOT NULL ,
OWNERSHIP_TYPE VARCHAR(45) NULL,
COMPLIANCE VARCHAR(100) NULL,
PRIORITY INT NOT NULL,
ACTIVE INT NOT NULL,
UPDATED INT NULL,
PRIORITY INTEGER NOT NULL,
ACTIVE INTEGER NOT NULL,
UPDATED INTEGER NULL,
PRIMARY KEY (ID) ,
CONSTRAINT FK_DM_PROFILE_DM_POLICY
FOREIGN KEY (PROFILE_ID )
@ -154,11 +177,11 @@ CREATE TABLE DM_POLICY (
CREATE TABLE DM_DEVICE_POLICY (
ID INT NOT NULL IDENTITY ,
DEVICE_ID INT NOT NULL ,
ENROLMENT_ID INT NOT NULL,
ID INTEGER NOT NULL IDENTITY ,
DEVICE_ID INTEGER NOT NULL ,
ENROLMENT_ID INTEGER NOT NULL,
DEVICE VARBINARY(max) NOT NULL,
POLICY_ID INT NOT NULL ,
POLICY_ID INTEGER NOT NULL ,
PRIMARY KEY (ID) ,
CONSTRAINT FK_POLICY_DEVICE_POLICY
FOREIGN KEY (POLICY_ID )
@ -176,9 +199,9 @@ CREATE TABLE DM_DEVICE_POLICY (
CREATE TABLE DM_DEVICE_TYPE_POLICY (
ID INT NOT NULL ,
DEVICE_TYPE_ID INT NOT NULL ,
POLICY_ID INT NOT NULL ,
ID INTEGER NOT NULL ,
DEVICE_TYPE_ID INTEGER NOT NULL ,
POLICY_ID INTEGER NOT NULL ,
PRIMARY KEY (ID) ,
CONSTRAINT FK_DEVICE_TYPE_POLICY
FOREIGN KEY (POLICY_ID )
@ -197,11 +220,11 @@ CREATE TABLE DM_DEVICE_TYPE_POLICY (
CREATE TABLE DM_PROFILE_FEATURES (
ID INT NOT NULL IDENTITY,
PROFILE_ID INT NOT NULL,
ID INTEGER NOT NULL IDENTITY,
PROFILE_ID INTEGER NOT NULL,
FEATURE_CODE VARCHAR(100) NOT NULL,
DEVICE_TYPE_ID INT NOT NULL,
TENANT_ID INT NOT NULL ,
DEVICE_TYPE_ID INTEGER NOT NULL,
TENANT_ID INTEGER NOT NULL ,
CONTENT VARBINARY(max) NULL DEFAULT NULL,
PRIMARY KEY (ID),
CONSTRAINT FK_DM_PROFILE_DM_POLICY_FEATURES
@ -215,9 +238,9 @@ CREATE TABLE DM_PROFILE_FEATURES (
CREATE TABLE DM_ROLE_POLICY (
ID INT NOT NULL IDENTITY ,
ID INTEGER NOT NULL IDENTITY ,
ROLE_NAME VARCHAR(45) NOT NULL ,
POLICY_ID INT NOT NULL ,
POLICY_ID INTEGER NOT NULL ,
PRIMARY KEY (ID) ,
CONSTRAINT FK_ROLE_POLICY_POLICY
FOREIGN KEY (POLICY_ID )
@ -230,8 +253,8 @@ CREATE TABLE DM_ROLE_POLICY (
CREATE TABLE DM_USER_POLICY (
ID INT NOT NULL IDENTITY ,
POLICY_ID INT NOT NULL ,
ID INTEGER NOT NULL IDENTITY ,
POLICY_ID INTEGER NOT NULL ,
USERNAME VARCHAR(45) NOT NULL ,
PRIMARY KEY (ID) ,
CONSTRAINT DM_POLICY_USER_POLICY
@ -243,12 +266,12 @@ CREATE TABLE DM_USER_POLICY (
CREATE TABLE DM_DEVICE_POLICY_APPLIED (
ID INT NOT NULL IDENTITY ,
DEVICE_ID INT NOT NULL ,
ENROLMENT_ID INT NOT NULL,
POLICY_ID INT NOT NULL ,
ID INTEGER NOT NULL IDENTITY ,
DEVICE_ID INTEGER NOT NULL ,
ENROLMENT_ID INTEGER NOT NULL,
POLICY_ID INTEGER NOT NULL ,
POLICY_CONTENT VARBINARY(max) NULL ,
TENANT_ID INT NOT NULL,
TENANT_ID INTEGER NOT NULL,
APPLIED SMALLINT NULL ,
CREATED_TIME DATETIME2(0) NULL ,
UPDATED_TIME DATETIME2(0) NULL ,
@ -264,8 +287,8 @@ CREATE TABLE DM_USER_POLICY (
CREATE TABLE DM_CRITERIA (
ID INT NOT NULL IDENTITY,
TENANT_ID INT NOT NULL,
ID INTEGER NOT NULL IDENTITY,
TENANT_ID INTEGER NOT NULL,
NAME VARCHAR(50) NULL,
PRIMARY KEY (ID)
);
@ -273,9 +296,9 @@ CREATE TABLE DM_CRITERIA (
CREATE TABLE DM_POLICY_CRITERIA (
ID INT NOT NULL IDENTITY,
CRITERIA_ID INT NOT NULL,
POLICY_ID INT NOT NULL,
ID INTEGER NOT NULL IDENTITY,
CRITERIA_ID INTEGER NOT NULL,
POLICY_ID INTEGER NOT NULL,
PRIMARY KEY (ID),
CONSTRAINT FK_CRITERIA_POLICY_CRITERIA
FOREIGN KEY (CRITERIA_ID)
@ -290,8 +313,8 @@ CREATE TABLE DM_POLICY_CRITERIA (
);
CREATE TABLE DM_POLICY_CRITERIA_PROPERTIES (
ID INT NOT NULL IDENTITY,
POLICY_CRITERION_ID INT NOT NULL,
ID INTEGER NOT NULL IDENTITY,
POLICY_CRITERION_ID INTEGER NOT NULL,
PROP_KEY VARCHAR(45) NULL,
PROP_VALUE VARCHAR(100) NULL,
CONTENT VARBINARY(max) NULL ,
@ -304,35 +327,35 @@ CREATE TABLE DM_POLICY_CRITERIA_PROPERTIES (
);
CREATE TABLE DM_POLICY_COMPLIANCE_STATUS (
ID INT NOT NULL IDENTITY,
DEVICE_ID INT NOT NULL,
ENROLMENT_ID INT NOT NULL,
POLICY_ID INT NOT NULL,
TENANT_ID INT NOT NULL,
STATUS INT NULL,
ID INTEGER NOT NULL IDENTITY,
DEVICE_ID INTEGER NOT NULL,
ENROLMENT_ID INTEGER NOT NULL,
POLICY_ID INTEGER NOT NULL,
TENANT_ID INTEGER NOT NULL,
STATUS INTEGER NULL,
LAST_SUCCESS_TIME DATETIME2(0) NULL,
LAST_REQUESTED_TIME DATETIME2(0) NULL,
LAST_FAILED_TIME DATETIME2(0) NULL,
ATTEMPTS INT NULL,
ATTEMPTS INTEGER NULL,
PRIMARY KEY (ID)
);
CREATE TABLE DM_POLICY_CHANGE_MGT (
ID INT NOT NULL IDENTITY,
POLICY_ID INT NOT NULL,
DEVICE_TYPE_ID INT NOT NULL,
TENANT_ID INT NOT NULL,
ID INTEGER NOT NULL IDENTITY,
POLICY_ID INTEGER NOT NULL,
DEVICE_TYPE_ID INTEGER NOT NULL,
TENANT_ID INTEGER NOT NULL,
PRIMARY KEY (ID)
);
CREATE TABLE DM_POLICY_COMPLIANCE_FEATURES (
ID INT NOT NULL IDENTITY,
COMPLIANCE_STATUS_ID INT NOT NULL,
TENANT_ID INT NOT NULL,
ID INTEGER NOT NULL IDENTITY,
COMPLIANCE_STATUS_ID INTEGER NOT NULL,
TENANT_ID INTEGER NOT NULL,
FEATURE_CODE VARCHAR(100) NOT NULL,
STATUS INT NULL,
STATUS INTEGER NULL,
PRIMARY KEY (ID),
CONSTRAINT FK_COMPLIANCE_FEATURES_STATUS
FOREIGN KEY (COMPLIANCE_STATUS_ID)
@ -342,10 +365,10 @@ CREATE TABLE DM_POLICY_COMPLIANCE_FEATURES (
);
CREATE TABLE DM_DEVICE_GROUP_POLICY (
ID INT NOT NULL IDENTITY,
DEVICE_GROUP_ID INT NOT NULL,
POLICY_ID INT NOT NULL,
TENANT_ID INT NOT NULL,
ID INTEGER NOT NULL IDENTITY,
DEVICE_GROUP_ID INTEGER NOT NULL,
POLICY_ID INTEGER NOT NULL,
TENANT_ID INTEGER NOT NULL,
PRIMARY KEY (ID),
CONSTRAINT FK_DM_DEVICE_GROUP_POLICY
FOREIGN KEY (DEVICE_GROUP_ID)
@ -370,7 +393,7 @@ CREATE TABLE DM_APPLICATION (
LOCATION_URL VARCHAR(100) DEFAULT NULL,
IMAGE_URL VARCHAR(100) DEFAULT NULL,
APP_PROPERTIES VARBINARY(max) NULL,
MEMORY_USAGE INTEGER(10) NULL,
MEMORY_USAGE INTEGER NULL,
TENANT_ID INTEGER NOT NULL,
PRIMARY KEY (ID)
);
@ -405,12 +428,12 @@ CREATE TABLE DM_NOTIFICATION (
);
-- NOTIFICATION TABLE END --
DROP TABLE IF EXISTS DM_DEVICE_INFO;
IF EXISTS (SELECT * FROM sys.objects WHERE name = 'DM_DEVICE_INFO' and type = 'u')
DROP TABLE DM_DEVICE_INFO;
CREATE TABLE DM_DEVICE_INFO (
ID INTEGER IDENTITY NOT NULL,
DEVICE_ID INT NULL,
DEVICE_ID INTEGER NULL,
KEY_FIELD VARCHAR(45) NULL,
VALUE_FIELD VARCHAR(100) NULL,
PRIMARY KEY (ID),
@ -423,11 +446,12 @@ CREATE TABLE DM_DEVICE_INFO (
CREATE INDEX DM_DEVICE_INFO_DEVICE_idx ON DM_DEVICE_INFO (DEVICE_ID ASC);
DROP TABLE IF EXISTS DM_DEVICE_LOCATION;
IF EXISTS (SELECT * FROM sys.objects WHERE name = 'DM_DEVICE_LOCATION' and type = 'u')
DROP TABLE DM_DEVICE_LOCATION;
CREATE TABLE DM_DEVICE_LOCATION (
ID INTEGER IDENTITY NOT NULL,
DEVICE_ID INT NULL,
DEVICE_ID INTEGER NULL,
LATITUDE FLOAT NULL,
LONGITUDE FLOAT NULL,
STREET1 VARCHAR(45) NULL,
@ -447,11 +471,12 @@ CREATE TABLE DM_DEVICE_LOCATION (
CREATE INDEX DM_DEVICE_LOCATION_DEVICE_idx ON DM_DEVICE_LOCATION (DEVICE_ID ASC);
DROP TABLE IF EXISTS DM_DEVICE_DETAIL;
IF EXISTS (SELECT * FROM sys.objects WHERE name = 'DM_DEVICE_DETAIL' and type = 'u')
DROP TABLE DM_DEVICE_DETAIL;
CREATE TABLE DM_DEVICE_DETAIL (
ID INT NOT NULL IDENTITY,
DEVICE_ID INT NOT NULL,
ID INTEGER NOT NULL IDENTITY,
DEVICE_ID INTEGER NOT NULL,
DEVICE_MODEL VARCHAR(45) NULL,
VENDOR VARCHAR(45) NULL,
OS_VERSION VARCHAR(45) NULL,
@ -465,7 +490,7 @@ CREATE TABLE DM_DEVICE_DETAIL (
CPU_USAGE DECIMAL(5) NULL,
TOTAL_RAM_MEMORY DECIMAL(30,3) NULL,
AVAILABLE_RAM_MEMORY DECIMAL(30,3) NULL,
PLUGGED_IN INT NULL,
PLUGGED_IN INTEGER NULL,
UPDATE_TIMESTAMP BIGINT NOT NULL,
PRIMARY KEY (ID),
CONSTRAINT FK_DM_DEVICE_DETAILS_DEVICE

Loading…
Cancel
Save