Refactored postgresql.sql DB script

revert-70aa11f8
Dileesha Rajapakse 9 years ago
parent 1b62efebc5
commit 935455f700

@ -1,11 +1,9 @@
DROP TABLE IF EXISTS DM_DEVICE_TYPE;
CREATE TABLE DM_DEVICE_TYPE (
CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE (
ID BIGSERIAL PRIMARY KEY,
NAME VARCHAR(300) DEFAULT NULL
);
DROP TABLE IF EXISTS DM_DEVICE;
CREATE TABLE DM_DEVICE (
CREATE TABLE IF NOT EXISTS DM_DEVICE (
ID BIGSERIAL NOT NULL PRIMARY KEY,
DESCRIPTION TEXT DEFAULT NULL,
NAME VARCHAR(100) DEFAULT NULL,
@ -16,8 +14,7 @@ CREATE TABLE DM_DEVICE (
REFERENCES DM_DEVICE_TYPE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
);
DROP TABLE IF EXISTS DM_OPERATION;
CREATE TABLE DM_OPERATION (
CREATE TABLE IF NOT EXISTS DM_OPERATION (
ID BIGSERIAL NOT NULL PRIMARY KEY,
TYPE VARCHAR(50) NOT NULL,
CREATED_TIMESTAMP TIMESTAMP NOT NULL,
@ -25,8 +22,7 @@ CREATE TABLE DM_OPERATION (
OPERATION_CODE VARCHAR(1000) NOT NULL
);
DROP TABLE IF EXISTS DM_CONFIG_OPERATION;
CREATE TABLE DM_CONFIG_OPERATION (
CREATE TABLE IF NOT EXISTS DM_CONFIG_OPERATION (
OPERATION_ID INTEGER NOT NULL,
OPERATION_CONFIG BYTEA DEFAULT NULL,
PRIMARY KEY (OPERATION_ID),
@ -34,8 +30,7 @@ CREATE TABLE DM_CONFIG_OPERATION (
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
);
DROP TABLE IF EXISTS DM_COMMAND_OPERATION;
CREATE TABLE DM_COMMAND_OPERATION (
CREATE TABLE IF NOT EXISTS DM_COMMAND_OPERATION (
OPERATION_ID INTEGER NOT NULL,
ENABLED BOOLEAN NOT NULL DEFAULT FALSE,
PRIMARY KEY (OPERATION_ID),
@ -43,8 +38,7 @@ CREATE TABLE DM_COMMAND_OPERATION (
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
);
DROP TABLE IF EXISTS DM_POLICY_OPERATION;
CREATE TABLE DM_POLICY_OPERATION (
CREATE TABLE IF NOT EXISTS DM_POLICY_OPERATION (
OPERATION_ID INTEGER NOT NULL,
ENABLED INTEGER NOT NULL DEFAULT 0,
OPERATION_DETAILS BYTEA DEFAULT NULL,
@ -53,8 +47,7 @@ CREATE TABLE DM_POLICY_OPERATION (
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
);
DROP TABLE IF EXISTS DM_PROFILE_OPERATION;
CREATE TABLE DM_PROFILE_OPERATION (
CREATE TABLE IF NOT EXISTS DM_PROFILE_OPERATION (
OPERATION_ID INTEGER NOT NULL,
ENABLED INTEGER NOT NULL DEFAULT 0,
OPERATION_DETAILS BYTEA DEFAULT NULL,
@ -63,8 +56,7 @@ CREATE TABLE DM_PROFILE_OPERATION (
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
);
DROP TABLE IF EXISTS DM_ENROLMENT;
CREATE TABLE DM_ENROLMENT (
CREATE TABLE IF NOT EXISTS DM_ENROLMENT (
ID BIGSERIAL NOT NULL PRIMARY KEY,
DEVICE_ID INTEGER NOT NULL,
OWNER VARCHAR(50) NOT NULL,
@ -77,8 +69,7 @@ CREATE TABLE DM_ENROLMENT (
DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
);
DROP TABLE IF EXISTS DM_ENROLMENT_OP_MAPPING;
CREATE TABLE DM_ENROLMENT_OP_MAPPING (
CREATE TABLE IF NOT EXISTS DM_ENROLMENT_OP_MAPPING (
ID BIGSERIAL NOT NULL PRIMARY KEY,
ENROLMENT_ID INTEGER NOT NULL,
OPERATION_ID INTEGER NOT NULL,
@ -89,8 +80,7 @@ CREATE TABLE DM_ENROLMENT_OP_MAPPING (
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
);
DROP TABLE IF EXISTS DM_DEVICE_OPERATION_RESPONSE;
CREATE TABLE DM_DEVICE_OPERATION_RESPONSE (
CREATE TABLE IF NOT EXISTS DM_DEVICE_OPERATION_RESPONSE (
ID BIGSERIAL NOT NULL PRIMARY KEY,
DEVICE_ID INTEGER NOT NULL,
OPERATION_ID INTEGER NOT NULL,
@ -103,7 +93,6 @@ CREATE TABLE DM_DEVICE_OPERATION_RESPONSE (
-- POLICY RELATED TABLES ---
DROP TABLE IF EXISTS DM_PROFILE;
CREATE TABLE DM_PROFILE (
ID BIGSERIAL NOT NULL PRIMARY KEY,
PROFILE_NAME VARCHAR(45) NOT NULL ,
@ -118,7 +107,6 @@ CREATE TABLE DM_PROFILE (
ON UPDATE NO ACTION
);
DROP TABLE IF EXISTS DM_POLICY;
CREATE TABLE DM_POLICY (
ID BIGSERIAL NOT NULL PRIMARY KEY,
NAME VARCHAR(45) DEFAULT NULL ,
@ -137,7 +125,6 @@ CREATE TABLE DM_POLICY (
ON UPDATE NO ACTION
);
DROP TABLE IF EXISTS DM_DEVICE_POLICY;
CREATE TABLE DM_DEVICE_POLICY (
ID BIGSERIAL NOT NULL PRIMARY KEY,
DEVICE_ID INTEGER NOT NULL ,
@ -156,7 +143,6 @@ CREATE TABLE DM_DEVICE_POLICY (
ON UPDATE NO ACTION
);
DROP TABLE IF EXISTS DM_DEVICE_TYPE_POLICY;
CREATE TABLE DM_DEVICE_TYPE_POLICY (
ID INTEGER NOT NULL,
DEVICE_TYPE_ID INTEGER NOT NULL ,
@ -174,7 +160,6 @@ CREATE TABLE DM_DEVICE_TYPE_POLICY (
ON UPDATE NO ACTION
);
DROP TABLE IF EXISTS DM_PROFILE_FEATURES;
CREATE TABLE DM_PROFILE_FEATURES (
ID BIGSERIAL NOT NULL PRIMARY KEY,
PROFILE_ID INTEGER NOT NULL,
@ -189,7 +174,6 @@ CREATE TABLE DM_PROFILE_FEATURES (
ON UPDATE NO ACTION
);
DROP TABLE IF EXISTS DM_ROLE_POLICY;
CREATE TABLE DM_ROLE_POLICY (
ID BIGSERIAL NOT NULL PRIMARY KEY,
ROLE_NAME VARCHAR(45) NOT NULL ,
@ -201,7 +185,6 @@ CREATE TABLE DM_ROLE_POLICY (
ON UPDATE NO ACTION
);
DROP TABLE IF EXISTS DM_USER_POLICY;
CREATE TABLE DM_USER_POLICY (
ID BIGSERIAL NOT NULL PRIMARY KEY,
POLICY_ID INT NOT NULL ,
@ -213,7 +196,6 @@ CREATE TABLE DM_USER_POLICY (
ON UPDATE NO ACTION
);
DROP TABLE IF EXISTS DM_DEVICE_POLICY_APPLIED;
CREATE TABLE DM_DEVICE_POLICY_APPLIED (
ID BIGSERIAL NOT NULL PRIMARY KEY,
DEVICE_ID INTEGER NOT NULL ,
@ -237,15 +219,13 @@ CREATE TABLE DM_DEVICE_POLICY_APPLIED (
ON UPDATE NO ACTION
);
DROP TABLE IF EXISTS DM_CRITERIA;
CREATE TABLE DM_CRITERIA (
CREATE TABLE IF NOT EXISTS DM_CRITERIA (
ID BIGSERIAL NOT NULL PRIMARY KEY,
TENANT_ID INT NOT NULL,
NAME VARCHAR(50) NULL
);
DROP TABLE IF EXISTS DM_POLICY_CRITERIA;
CREATE TABLE DM_POLICY_CRITERIA (
CREATE TABLE IF NOT EXISTS DM_POLICY_CRITERIA (
ID BIGSERIAL NOT NULL PRIMARY KEY,
CRITERIA_ID INT NOT NULL,
POLICY_ID INT NOT NULL,
@ -261,8 +241,7 @@ CREATE TABLE DM_POLICY_CRITERIA (
ON UPDATE NO ACTION
);
DROP TABLE IF EXISTS DM_POLICY_CRITERIA_PROPERTIES;
CREATE TABLE DM_POLICY_CRITERIA_PROPERTIES (
CREATE TABLE IF NOT EXISTS DM_POLICY_CRITERIA_PROPERTIES (
ID BIGSERIAL NOT NULL PRIMARY KEY,
POLICY_CRITERION_ID INT NOT NULL,
PROP_KEY VARCHAR(45) NULL,
@ -276,8 +255,7 @@ CREATE TABLE DM_POLICY_CRITERIA_PROPERTIES (
);
COMMENT ON COLUMN DM_POLICY_CRITERIA_PROPERTIES.CONTENT IS 'This is used to ';
DROP TABLE IF EXISTS DM_POLICY_COMPLIANCE_STATUS;
CREATE TABLE DM_POLICY_COMPLIANCE_STATUS (
CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_STATUS (
ID BIGSERIAL NOT NULL PRIMARY KEY,
DEVICE_ID INTEGER NOT NULL,
ENROLMENT_ID INTEGER NOT NULL,
@ -296,16 +274,14 @@ CREATE TABLE DM_POLICY_COMPLIANCE_STATUS (
);
CREATE UNIQUE INDEX DEVICE_ID_UNIQUE ON DM_POLICY_COMPLIANCE_STATUS (DEVICE_ID ASC);
DROP TABLE IF EXISTS DM_POLICY_CHANGE_MGT;
CREATE TABLE DM_POLICY_CHANGE_MGT (
CREATE TABLE IF NOT EXISTS DM_POLICY_CHANGE_MGT (
ID BIGSERIAL NOT NULL PRIMARY KEY,
POLICY_ID INTEGER NOT NULL,
DEVICE_TYPE_ID INTEGER NOT NULL,
TENANT_ID INTEGER NOT NULL
);
DROP TABLE IF EXISTS DM_POLICY_COMPLIANCE_FEATURES;
CREATE TABLE DM_POLICY_COMPLIANCE_FEATURES (
CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_FEATURES (
ID BIGSERIAL NOT NULL PRIMARY KEY,
COMPLIANCE_STATUS_ID INTEGER NOT NULL,
TENANT_ID INTEGER NOT NULL,
@ -318,8 +294,7 @@ CREATE TABLE DM_POLICY_COMPLIANCE_FEATURES (
ON UPDATE NO ACTION
);
DROP TABLE IF EXISTS DM_ENROLMENT;
CREATE TABLE DM_ENROLMENT (
CREATE TABLE IF NOT EXISTS DM_ENROLMENT (
ID BIGSERIAL NOT NULL PRIMARY KEY,
DEVICE_ID INTEGER NOT NULL,
OWNER VARCHAR(50) NOT NULL,
@ -332,8 +307,7 @@ CREATE TABLE DM_ENROLMENT (
DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
);
DROP TABLE IF EXISTS DM_APPLICATION;
CREATE TABLE DM_APPLICATION (
CREATE TABLE IF NOT EXISTS DM_APPLICATION (
ID BIGSERIAL NOT NULL PRIMARY KEY,
NAME VARCHAR(50) NOT NULL,
APP_IDENTIFIER VARCHAR(150) NOT NULL,
@ -350,8 +324,7 @@ CREATE TABLE DM_APPLICATION (
-- POLICY RELATED TABLES FINISHED --
-- NOTIFICATION TABLE --
DROP TABLE IF EXISTS DM_NOTIFICATION;
CREATE TABLE DM_NOTIFICATION (
CREATE TABLE IF NOT EXISTS DM_NOTIFICATION (
NOTIFICATION_ID BIGSERIAL NOT NULL PRIMARY KEY,
DEVICE_ID INTEGER NOT NULL,
OPERATION_ID INTEGER NOT NULL,

Loading…
Cancel
Save