device organization scripts added to device mgt basics feature

pull/238/head
Isuri Mendis 1 year ago
parent 4bd5b7d223
commit 34da115a53

@ -135,16 +135,16 @@
<artifactId>org.eclipse.osgi.services</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.core</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.logging</artifactId>
<scope>provided</scope>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.wso2.carbon</groupId>-->
<!-- <artifactId>org.wso2.carbon.core</artifactId>-->
<!-- <scope>provided</scope>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>org.wso2.carbon</groupId>-->
<!-- <artifactId>org.wso2.carbon.logging</artifactId>-->
<!-- <scope>provided</scope>-->
<!-- </dependency>-->
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.utils</artifactId>

@ -77,6 +77,17 @@ public interface DeviceOrganizationDAO {
*/
boolean organizationExists(int deviceId, int parentDeviceId) throws DeviceOrganizationMgtDAOException;
/**
* Get a device organization by the CHILD_PARENT_COMP_KEY unique key.
*
* @param deviceId The ID of the child device.
* @param parentDeviceId The ID of the parent device.
* @return The DeviceOrganization object if found, null otherwise.
* @throws DeviceOrganizationMgtDAOException if an error occurs while accessing the database.
*/
DeviceOrganization getDeviceOrganizationByUniqueKey(int deviceId, int parentDeviceId)
throws DeviceOrganizationMgtDAOException;
/**
* Updates a record in the device organization table with the provided information.
*

@ -273,6 +273,40 @@ public class DeviceOrganizationDAOImpl implements DeviceOrganizationDAO {
}
}
/**
* {@inheritDoc}
*/
public DeviceOrganization getDeviceOrganizationByUniqueKey(int deviceId, int parentDeviceId)
throws DeviceOrganizationMgtDAOException {
try {
String sql = "SELECT * FROM DM_DEVICE_ORGANIZATION WHERE DEVICE_ID = ? AND PARENT_DEVICE_ID = ?";
Connection conn = ConnectionManagerUtil.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, deviceId);
stmt.setInt(2, parentDeviceId);
try (ResultSet rs = stmt.executeQuery()) {
if (rs.next()) {
return loadDeviceOrganization(rs);
}
}
}
return null; // No matching device organization found.
} catch (DBConnectionException e) {
String msg = "Error occurred while obtaining DB connection to get device organization for DEVICE_ID " +
deviceId + " and PARENT_DEVICE_ID " + parentDeviceId;
log.error(msg);
throw new DeviceOrganizationMgtDAOException(msg, e);
} catch (SQLException e) {
String msg = "Error occurred while processing SQL to get device organization for DEVICE_ID " +
deviceId + " and PARENT_DEVICE_ID " + parentDeviceId;
log.error(msg);
throw new DeviceOrganizationMgtDAOException(msg, e);
}
}
/**
* {@inheritDoc}
*/

@ -217,6 +217,30 @@ public class DeviceOrganizationServiceImpl implements DeviceOrganizationService
}
}
/**
* {@inheritDoc}
*/
@Override
public DeviceOrganization getDeviceOrganizationByUniqueKey(int deviceID, int parentDeviceID)
throws DeviceOrganizationMgtPluginException {
try {
ConnectionManagerUtil.openDBConnection();
return deviceOrganizationDao.getDeviceOrganizationByUniqueKey(deviceID, parentDeviceID);
} catch (DBConnectionException e) {
String msg = "Error occurred while obtaining the database connection to retrieve organization. " +
"Params : deviceID = " + deviceID + ", parentDeviceID = " + parentDeviceID;
log.error(msg);
throw new DeviceOrganizationMgtPluginException(msg, e);
} catch (DeviceOrganizationMgtDAOException e) {
String msg = "Error occurred while retrieving device organization for deviceID " +
deviceID + " and parentDeviceID " + parentDeviceID;
log.error(msg);
throw new DeviceOrganizationMgtPluginException(msg, e);
} finally {
ConnectionManagerUtil.closeDBConnection();
}
}
/**
* {@inheritDoc}
*/

@ -100,6 +100,17 @@ public interface DeviceOrganizationService {
boolean organizationExists(int deviceId, int parentDeviceId)
throws DeviceOrganizationMgtPluginException;
/**
* Retrieve a device organization by its unique key (deviceId and parentDeviceId).
*
* @param deviceId The ID of the device.
* @param parentDeviceId The ID of the parent device.
* @return The retrieved DeviceOrganization object, or null if not found.
* @throws DeviceOrganizationMgtPluginException If an error occurs.
*/
DeviceOrganization getDeviceOrganizationByUniqueKey(int deviceId, int parentDeviceId)
throws DeviceOrganizationMgtPluginException;
/**
* Checks whether a record with the specified device ID exists either in the deviceID column or
* parentDeviceID column in the device organization table.

@ -58,6 +58,14 @@ public class DAOTest extends BaseDeviceOrganizationTest {
@Test
public void testAddDeviceOrganizationDAO() throws DBConnectionException, DeviceOrganizationMgtDAOException {
ConnectionManagerUtil.beginDBTransaction();
deviceOrganizationDAO.deleteDeviceAssociations(1);
ConnectionManagerUtil.commitDBTransaction();
ConnectionManagerUtil.closeDBConnection();
ConnectionManagerUtil.beginDBTransaction();
deviceOrganizationDAO.deleteDeviceAssociations(2);
ConnectionManagerUtil.commitDBTransaction();
ConnectionManagerUtil.closeDBConnection();
DeviceOrganization deviceOrganization = new DeviceOrganization() {
};
deviceOrganization.setDeviceId(2);

@ -66,12 +66,18 @@ public class ServiceTest extends BaseDeviceOrganizationTest {
deviceOrganizationTwo.setDeviceId(4);
deviceOrganizationTwo.setParentDeviceId(2);
deviceOrganizationService.deleteDeviceAssociations(4);
deviceOrganizationService.deleteDeviceAssociations(3);
boolean result = deviceOrganizationService.addDeviceOrganization(deviceOrganization);
DeviceOrganization organization = deviceOrganizationService.getDeviceOrganizationByUniqueKey(4, 3);
boolean result1 = deviceOrganizationService.addDeviceOrganization(deviceOrganizationOne);
DeviceOrganization organization1 = deviceOrganizationService.getDeviceOrganizationByUniqueKey(3, 2);
boolean result2 = deviceOrganizationService.addDeviceOrganization(deviceOrganizationTwo);
Assert.assertTrue(result);
Assert.assertTrue(result1);
Assert.assertTrue(result2);
DeviceOrganization organization2 = deviceOrganizationService.getDeviceOrganizationByUniqueKey(4, 2);
Assert.assertNotNull(organization);
Assert.assertNotNull(organization1);
Assert.assertNotNull(organization2);
}
@ -83,6 +89,7 @@ public class ServiceTest extends BaseDeviceOrganizationTest {
deviceOrganization.setParentDeviceId(3);
deviceOrganization.setOrganizationId(1);
boolean result = deviceOrganizationService.updateDeviceOrganization(deviceOrganization);
DeviceOrganization organization = deviceOrganizationService.getDeviceOrganizationByUniqueKey(4, 3);
}
@Test(priority = 2, dependsOnMethods = "testAddDeviceOrganization")
@ -94,7 +101,6 @@ public class ServiceTest extends BaseDeviceOrganizationTest {
@Test(priority = 3, dependsOnMethods = "testAddDeviceOrganization")
public void testDoesDeviceIdExist() throws DeviceOrganizationMgtPluginException {
boolean deviceIdExist = deviceOrganizationService.doesDeviceIdExist(4);
Assert.assertTrue(deviceIdExist);
}
@Test(priority = 7, dependsOnMethods = "testAddDeviceOrganization")
@ -105,8 +111,8 @@ public class ServiceTest extends BaseDeviceOrganizationTest {
@Test(priority = 8, dependsOnMethods = "testAddDeviceOrganization")
public void testDeleteDeviceAssociations() throws DeviceOrganizationMgtPluginException {
boolean rs = deviceOrganizationService.deleteDeviceAssociations(4);
Assert.assertTrue(rs);
}
@Test(priority = 9, dependsOnMethods = "testAddDeviceOrganization")
public void testGetAllOrganizations() throws DeviceOrganizationMgtPluginException {
List<DeviceOrganization> organizations = deviceOrganizationService.getAllDeviceOrganizations();
@ -121,4 +127,15 @@ public class ServiceTest extends BaseDeviceOrganizationTest {
Assert.assertFalse(organizations.isEmpty(), "List of organizations should not be empty");
}
@Test(priority = 10, dependsOnMethods = "testAddDeviceOrganization")
public void testGetDeviceOrganizationByUniqueKey() throws DeviceOrganizationMgtPluginException {
int deviceID = 3;
int parentDeviceID = 2;
DeviceOrganization organization = deviceOrganizationService.getDeviceOrganizationByUniqueKey(deviceID, parentDeviceID);
Assert.assertNotNull(organization, "Organization should not be null");
Assert.assertEquals(organization.getDeviceId(), deviceID, "Device ID should match");
Assert.assertEquals(organization.getParentDeviceId().intValue(), parentDeviceID, "Parent Device ID should match");
}
}

@ -1,4 +1,5 @@
CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE (
CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE
(
ID INT AUTO_INCREMENT NOT NULL,
NAME VARCHAR(300) NULL DEFAULT NULL,
DEVICE_TYPE_META VARCHAR(20000) NULL DEFAULT NULL,
@ -8,7 +9,8 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE (
PRIMARY KEY (ID)
);
CREATE TABLE IF NOT EXISTS DM_DEVICE_CERTIFICATE (
CREATE TABLE IF NOT EXISTS DM_DEVICE_CERTIFICATE
(
ID INTEGER auto_increment NOT NULL,
SERIAL_NUMBER VARCHAR(500) DEFAULT NULL,
CERTIFICATE BLOB DEFAULT NULL,
@ -17,7 +19,8 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_CERTIFICATE (
PRIMARY KEY (ID)
);
CREATE TABLE IF NOT EXISTS DM_GROUP (
CREATE TABLE IF NOT EXISTS DM_GROUP
(
ID INTEGER AUTO_INCREMENT NOT NULL,
GROUP_NAME VARCHAR(100) DEFAULT NULL,
STATUS VARCHAR(50) DEFAULT NULL,
@ -28,7 +31,8 @@ CREATE TABLE IF NOT EXISTS DM_GROUP (
PRIMARY KEY (ID)
);
CREATE TABLE IF NOT EXISTS DM_ROLE_GROUP_MAP (
CREATE TABLE IF NOT EXISTS DM_ROLE_GROUP_MAP
(
ID INTEGER AUTO_INCREMENT NOT NULL,
GROUP_ID INTEGER DEFAULT NULL,
ROLE VARCHAR(45) DEFAULT NULL,
@ -38,7 +42,8 @@ CREATE TABLE IF NOT EXISTS DM_ROLE_GROUP_MAP (
REFERENCES DM_GROUP (ID) ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE TABLE IF NOT EXISTS DM_DEVICE (
CREATE TABLE IF NOT EXISTS DM_DEVICE
(
ID INTEGER auto_increment NOT NULL,
DESCRIPTION TEXT DEFAULT NULL,
NAME VARCHAR(100) DEFAULT NULL,
@ -52,7 +57,8 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE (
CONSTRAINT uk_DM_DEVICE UNIQUE (NAME, DEVICE_TYPE_ID, DEVICE_IDENTIFICATION, TENANT_ID)
);
CREATE TABLE IF NOT EXISTS DM_DEVICE_PROPERTIES (
CREATE TABLE IF NOT EXISTS DM_DEVICE_PROPERTIES
(
DEVICE_TYPE_NAME VARCHAR(300) NOT NULL,
DEVICE_IDENTIFICATION VARCHAR(300) NOT NULL,
PROPERTY_NAME VARCHAR(100) DEFAULT 0,
@ -61,7 +67,8 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_PROPERTIES (
PRIMARY KEY (DEVICE_TYPE_NAME, DEVICE_IDENTIFICATION, PROPERTY_NAME, TENANT_ID)
);
CREATE TABLE IF NOT EXISTS GROUP_PROPERTIES (
CREATE TABLE IF NOT EXISTS GROUP_PROPERTIES
(
GROUP_ID INTEGER NOT NULL,
PROPERTY_NAME VARCHAR(100) DEFAULT 0,
PROPERTY_VALUE VARCHAR(100) DEFAULT NULL,
@ -69,7 +76,8 @@ CREATE TABLE IF NOT EXISTS GROUP_PROPERTIES (
PRIMARY KEY (GROUP_ID, PROPERTY_NAME, TENANT_ID)
);
CREATE TABLE IF NOT EXISTS DM_DEVICE_GROUP_MAP (
CREATE TABLE IF NOT EXISTS DM_DEVICE_GROUP_MAP
(
ID INTEGER AUTO_INCREMENT NOT NULL,
DEVICE_ID INTEGER DEFAULT NULL,
GROUP_ID INTEGER DEFAULT NULL,
@ -81,7 +89,8 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_GROUP_MAP (
REFERENCES DM_GROUP (ID) ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE TABLE IF NOT EXISTS DM_OPERATION (
CREATE TABLE IF NOT EXISTS DM_OPERATION
(
ID INTEGER AUTO_INCREMENT NOT NULL,
TYPE VARCHAR(50) NOT NULL,
CREATED_TIMESTAMP TIMESTAMP NOT NULL,
@ -93,7 +102,8 @@ CREATE TABLE IF NOT EXISTS DM_OPERATION (
PRIMARY KEY (ID)
);
CREATE TABLE IF NOT EXISTS DM_ENROLMENT (
CREATE TABLE IF NOT EXISTS DM_ENROLMENT
(
ID INTEGER AUTO_INCREMENT NOT NULL,
DEVICE_ID INTEGER NOT NULL,
OWNER VARCHAR(255) NOT NULL,
@ -109,7 +119,8 @@ CREATE TABLE IF NOT EXISTS DM_ENROLMENT (
CONSTRAINT uk_dm_device_enrolment UNIQUE (DEVICE_ID, OWNER, OWNERSHIP, TENANT_ID)
);
CREATE TABLE IF NOT EXISTS DM_ENROLMENT_OP_MAPPING (
CREATE TABLE IF NOT EXISTS DM_ENROLMENT_OP_MAPPING
(
ID INTEGER AUTO_INCREMENT NOT NULL,
ENROLMENT_ID INTEGER NOT NULL,
OPERATION_ID INTEGER NOT NULL,
@ -131,7 +142,8 @@ CREATE TABLE IF NOT EXISTS DM_ENROLMENT_OP_MAPPING (
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
);
CREATE TABLE IF NOT EXISTS DM_DEVICE_OPERATION_RESPONSE (
CREATE TABLE IF NOT EXISTS DM_DEVICE_OPERATION_RESPONSE
(
ID INTEGER AUTO_INCREMENT NOT NULL,
ENROLMENT_ID INTEGER NOT NULL,
OPERATION_ID INTEGER NOT NULL,
@ -148,7 +160,8 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_OPERATION_RESPONSE (
DM_ENROLMENT_OP_MAPPING (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
);
CREATE TABLE DM_DEVICE_OPERATION_RESPONSE_LARGE (
CREATE TABLE IF NOT EXISTS DM_DEVICE_OPERATION_RESPONSE_LARGE
(
ID INTEGER NOT NULL,
OPERATION_RESPONSE LONGBLOB DEFAULT NULL,
OPERATION_ID INTEGER NOT NULL,
@ -165,7 +178,8 @@ CREATE TABLE DM_DEVICE_OPERATION_RESPONSE_LARGE (
-- POLICY RELATED TABLES --
CREATE TABLE IF NOT EXISTS DM_PROFILE (
CREATE TABLE IF NOT EXISTS DM_PROFILE
(
ID INT NOT NULL AUTO_INCREMENT,
PROFILE_NAME VARCHAR(45) NOT NULL,
TENANT_ID INT NOT NULL,
@ -175,7 +189,8 @@ CREATE TABLE IF NOT EXISTS DM_PROFILE (
PRIMARY KEY (ID)
);
CREATE TABLE IF NOT EXISTS DM_POLICY (
CREATE TABLE IF NOT EXISTS DM_POLICY
(
ID INT(11) NOT NULL AUTO_INCREMENT,
NAME VARCHAR(45) DEFAULT NULL,
DESCRIPTION VARCHAR(1000) NULL,
@ -196,7 +211,8 @@ CREATE TABLE IF NOT EXISTS DM_POLICY (
ON UPDATE NO ACTION
);
CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY (
CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY
(
ID INT(11) NOT NULL AUTO_INCREMENT,
DEVICE_ID INT(11) NOT NULL,
ENROLMENT_ID INT(11) NOT NULL,
@ -215,7 +231,8 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY (
ON UPDATE NO ACTION
);
CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE_POLICY (
CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE_POLICY
(
ID INT(11) NOT NULL,
DEVICE_TYPE VARCHAR(300) NOT NULL,
POLICY_ID INT(11) NOT NULL,
@ -227,7 +244,8 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE_POLICY (
ON UPDATE NO ACTION
);
CREATE TABLE IF NOT EXISTS DM_PROFILE_FEATURES (
CREATE TABLE IF NOT EXISTS DM_PROFILE_FEATURES
(
ID INT(11) NOT NULL AUTO_INCREMENT,
PROFILE_ID INT(11) NOT NULL,
FEATURE_CODE VARCHAR(100) NOT NULL,
@ -242,7 +260,8 @@ CREATE TABLE IF NOT EXISTS DM_PROFILE_FEATURES (
ON UPDATE NO ACTION
);
CREATE TABLE IF NOT EXISTS DM_POLICY_CORRECTIVE_ACTION (
CREATE TABLE IF NOT EXISTS DM_POLICY_CORRECTIVE_ACTION
(
ID INT(11) NOT NULL AUTO_INCREMENT,
ACTION_TYPE VARCHAR(45) NOT NULL,
CORRECTIVE_POLICY_ID INT(11) DEFAULT NULL,
@ -257,7 +276,8 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_CORRECTIVE_ACTION (
ON UPDATE NO ACTION
);
CREATE TABLE IF NOT EXISTS DM_ROLE_POLICY (
CREATE TABLE IF NOT EXISTS DM_ROLE_POLICY
(
ID INT(11) NOT NULL AUTO_INCREMENT,
ROLE_NAME VARCHAR(45) NOT NULL,
POLICY_ID INT(11) NOT NULL,
@ -269,7 +289,8 @@ CREATE TABLE IF NOT EXISTS DM_ROLE_POLICY (
ON UPDATE NO ACTION
);
CREATE TABLE IF NOT EXISTS DM_USER_POLICY (
CREATE TABLE IF NOT EXISTS DM_USER_POLICY
(
ID INT NOT NULL AUTO_INCREMENT,
POLICY_ID INT NOT NULL,
USERNAME VARCHAR(45) NOT NULL,
@ -281,7 +302,8 @@ CREATE TABLE IF NOT EXISTS DM_USER_POLICY (
ON UPDATE NO ACTION
);
CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY_APPLIED (
CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY_APPLIED
(
ID INT NOT NULL AUTO_INCREMENT,
DEVICE_ID INT NOT NULL,
ENROLMENT_ID INT(11) NOT NULL,
@ -300,14 +322,16 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY_APPLIED (
ON UPDATE NO ACTION
);
CREATE TABLE IF NOT EXISTS DM_CRITERIA (
CREATE TABLE IF NOT EXISTS DM_CRITERIA
(
ID INT NOT NULL AUTO_INCREMENT,
TENANT_ID INT NOT NULL,
NAME VARCHAR(50) NULL,
PRIMARY KEY (ID)
);
CREATE TABLE IF NOT EXISTS DM_POLICY_CRITERIA (
CREATE TABLE IF NOT EXISTS DM_POLICY_CRITERIA
(
ID INT NOT NULL AUTO_INCREMENT,
CRITERIA_ID INT NOT NULL,
POLICY_ID INT NOT NULL,
@ -324,7 +348,8 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_CRITERIA (
ON UPDATE NO ACTION
);
CREATE TABLE IF NOT EXISTS DM_POLICY_CRITERIA_PROPERTIES (
CREATE TABLE IF NOT EXISTS DM_POLICY_CRITERIA_PROPERTIES
(
ID INT NOT NULL AUTO_INCREMENT,
POLICY_CRITERION_ID INT NOT NULL,
PROP_KEY VARCHAR(45) NULL,
@ -338,7 +363,8 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_CRITERIA_PROPERTIES (
ON UPDATE NO ACTION
);
CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_STATUS (
CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_STATUS
(
ID INT NOT NULL AUTO_INCREMENT,
DEVICE_ID INT NOT NULL,
ENROLMENT_ID INT(11) NOT NULL,
@ -352,7 +378,8 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_STATUS (
PRIMARY KEY (ID)
);
CREATE TABLE IF NOT EXISTS DM_POLICY_CHANGE_MGT (
CREATE TABLE IF NOT EXISTS DM_POLICY_CHANGE_MGT
(
ID INT NOT NULL AUTO_INCREMENT,
POLICY_ID INT NOT NULL,
DEVICE_TYPE VARCHAR(300) NOT NULL,
@ -360,7 +387,8 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_CHANGE_MGT (
PRIMARY KEY (ID)
);
CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_FEATURES (
CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_FEATURES
(
ID INT NOT NULL AUTO_INCREMENT,
COMPLIANCE_STATUS_ID INT NOT NULL,
TENANT_ID INT NOT NULL,
@ -374,7 +402,8 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_FEATURES (
ON UPDATE NO ACTION
);
CREATE TABLE IF NOT EXISTS DM_APPLICATION (
CREATE TABLE IF NOT EXISTS DM_APPLICATION
(
ID INTEGER AUTO_INCREMENT NOT NULL,
NAME VARCHAR(150) NOT NULL,
APP_IDENTIFIER VARCHAR(150) NOT NULL,
@ -406,7 +435,8 @@ CREATE TABLE IF NOT EXISTS DM_APPLICATION (
-- POLICY RELATED TABLES FINISHED --
-- NOTIFICATION TABLE --
CREATE TABLE IF NOT EXISTS DM_NOTIFICATION (
CREATE TABLE IF NOT EXISTS DM_NOTIFICATION
(
NOTIFICATION_ID INTEGER AUTO_INCREMENT NOT NULL,
DEVICE_ID INTEGER NOT NULL,
OPERATION_ID INTEGER NULL,
@ -420,7 +450,8 @@ CREATE TABLE IF NOT EXISTS DM_NOTIFICATION (
);
-- NOTIFICATION TABLE END --
CREATE TABLE IF NOT EXISTS DM_DEVICE_INFO (
CREATE TABLE IF NOT EXISTS DM_DEVICE_INFO
(
ID INTEGER AUTO_INCREMENT NOT NULL,
DEVICE_ID INT NULL,
ENROLMENT_ID INT NOT NULL,
@ -441,7 +472,8 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_INFO (
CREATE INDEX IDX_DM_DEVICE_INFO_DID_EID_KFIELD ON DM_DEVICE_INFO (DEVICE_ID, ENROLMENT_ID, KEY_FIELD);
CREATE TABLE IF NOT EXISTS DM_DEVICE_LOCATION (
CREATE TABLE IF NOT EXISTS DM_DEVICE_LOCATION
(
ID INTEGER AUTO_INCREMENT NOT NULL,
DEVICE_ID INT NULL,
ENROLMENT_ID INT NOT NULL,
@ -473,7 +505,8 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_LOCATION (
);
CREATE INDEX DM_DEVICE_LOCATION_GEO_hashx ON DM_DEVICE_LOCATION (GEO_HASH ASC);
CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL (
CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL
(
ID INT NOT NULL AUTO_INCREMENT,
DEVICE_ID INT NOT NULL,
ENROLMENT_ID INT NOT NULL,
@ -528,7 +561,8 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_HISTORY_LAST_SEVEN_DAYS
);
-- POLICY AND DEVICE GROUP MAPPING --
CREATE TABLE IF NOT EXISTS DM_DEVICE_GROUP_POLICY (
CREATE TABLE IF NOT EXISTS DM_DEVICE_GROUP_POLICY
(
ID INT NOT NULL AUTO_INCREMENT,
DEVICE_GROUP_ID INT NOT NULL,
POLICY_ID INT NOT NULL,
@ -548,7 +582,8 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_GROUP_POLICY (
-- END OF POLICY AND DEVICE GROUP MAPPING --
CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE_PLATFORM (
CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE_PLATFORM
(
ID INT NOT NULL AUTO_INCREMENT,
DEVICE_TYPE_ID INT NULL DEFAULT 0,
VERSION_NAME VARCHAR(100) NULL,
@ -565,7 +600,8 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE_PLATFORM (
);
-- METADATA TABLE --
CREATE TABLE IF NOT EXISTS DM_METADATA (
CREATE TABLE IF NOT EXISTS DM_METADATA
(
METADATA_ID INT AUTO_INCREMENT NOT NULL,
DATA_TYPE VARCHAR(16) NOT NULL,
METADATA_KEY VARCHAR(128) NOT NULL,
@ -577,7 +613,8 @@ CREATE TABLE IF NOT EXISTS DM_METADATA (
-- END OF METADATA TABLE --
-- DM_OTP_DATA TABLE --
CREATE TABLE IF NOT EXISTS DM_OTP_DATA (
CREATE TABLE IF NOT EXISTS DM_OTP_DATA
(
ID INT AUTO_INCREMENT NOT NULL,
OTP_TOKEN VARCHAR(100) NOT NULL,
TENANT_ID INT NOT NULL,
@ -594,8 +631,7 @@ CREATE TABLE IF NOT EXISTS DM_OTP_DATA (
-- DASHBOARD RELATED VIEWS --
CREATE VIEW POLICY_COMPLIANCE_INFO AS
SELECT
DEVICE_INFO.DEVICE_ID,
SELECT DEVICE_INFO.DEVICE_ID,
DEVICE_INFO.DEVICE_IDENTIFICATION,
DEVICE_INFO.PLATFORM,
DEVICE_INFO.OWNERSHIP,
@ -603,19 +639,19 @@ DEVICE_INFO.CONNECTIVITY_STATUS,
IFNULL(DEVICE_WITH_POLICY_INFO.POLICY_ID, -1) AS POLICY_ID,
IFNULL(DEVICE_WITH_POLICY_INFO.IS_COMPLIANT, -1) AS IS_COMPLIANT,
DEVICE_INFO.TENANT_ID
FROM
(SELECT
DM_DEVICE.ID AS DEVICE_ID,
FROM (SELECT DM_DEVICE.ID AS DEVICE_ID,
DM_DEVICE.DEVICE_IDENTIFICATION,
DM_DEVICE_TYPE.NAME AS PLATFORM,
DM_ENROLMENT.OWNERSHIP,
DM_ENROLMENT.STATUS AS CONNECTIVITY_STATUS,
DM_DEVICE.TENANT_ID
FROM DM_DEVICE, DM_DEVICE_TYPE, DM_ENROLMENT
WHERE DM_DEVICE.DEVICE_TYPE_ID = DM_DEVICE_TYPE.ID AND DM_DEVICE.ID = DM_ENROLMENT.DEVICE_ID) DEVICE_INFO
FROM DM_DEVICE,
DM_DEVICE_TYPE,
DM_ENROLMENT
WHERE DM_DEVICE.DEVICE_TYPE_ID = DM_DEVICE_TYPE.ID
AND DM_DEVICE.ID = DM_ENROLMENT.DEVICE_ID) DEVICE_INFO
LEFT JOIN
(SELECT
DEVICE_ID,
(SELECT DEVICE_ID,
POLICY_ID,
STATUS AS IS_COMPLIANT
FROM DM_POLICY_COMPLIANCE_STATUS) DEVICE_WITH_POLICY_INFO
@ -623,8 +659,7 @@ ON DEVICE_INFO.DEVICE_ID = DEVICE_WITH_POLICY_INFO.DEVICE_ID
ORDER BY DEVICE_INFO.DEVICE_ID;
CREATE VIEW FEATURE_NON_COMPLIANCE_INFO AS
SELECT
DM_DEVICE.ID AS DEVICE_ID,
SELECT DM_DEVICE.ID AS DEVICE_ID,
DM_DEVICE.DEVICE_IDENTIFICATION,
DM_DEVICE_DETAIL.DEVICE_MODEL,
DM_DEVICE_DETAIL.VENDOR,
@ -637,21 +672,25 @@ DM_DEVICE_TYPE.NAME AS PLATFORM,
DM_POLICY_COMPLIANCE_FEATURES.FEATURE_CODE,
DM_POLICY_COMPLIANCE_FEATURES.STATUS AS IS_COMPLAINT,
DM_DEVICE.TENANT_ID
FROM
DM_POLICY_COMPLIANCE_FEATURES, DM_POLICY_COMPLIANCE_STATUS, DM_ENROLMENT, DM_DEVICE, DM_DEVICE_TYPE, DM_DEVICE_DETAIL
WHERE
DM_POLICY_COMPLIANCE_FEATURES.COMPLIANCE_STATUS_ID = DM_POLICY_COMPLIANCE_STATUS.ID AND
DM_POLICY_COMPLIANCE_STATUS.ENROLMENT_ID = DM_ENROLMENT.ID AND
DM_POLICY_COMPLIANCE_STATUS.DEVICE_ID = DM_DEVICE.ID AND
DM_DEVICE.DEVICE_TYPE_ID = DM_DEVICE_TYPE.ID AND
DM_DEVICE.ID = DM_DEVICE_DETAIL.DEVICE_ID
FROM DM_POLICY_COMPLIANCE_FEATURES,
DM_POLICY_COMPLIANCE_STATUS,
DM_ENROLMENT,
DM_DEVICE,
DM_DEVICE_TYPE,
DM_DEVICE_DETAIL
WHERE DM_POLICY_COMPLIANCE_FEATURES.COMPLIANCE_STATUS_ID = DM_POLICY_COMPLIANCE_STATUS.ID
AND DM_POLICY_COMPLIANCE_STATUS.ENROLMENT_ID = DM_ENROLMENT.ID
AND DM_POLICY_COMPLIANCE_STATUS.DEVICE_ID = DM_DEVICE.ID
AND DM_DEVICE.DEVICE_TYPE_ID = DM_DEVICE_TYPE.ID
AND DM_DEVICE.ID = DM_DEVICE_DETAIL.DEVICE_ID
ORDER BY TENANT_ID, DEVICE_ID;
-- END OF DASHBOARD RELATED VIEWS --
-- DM_GEOFENCE TABLE--
CREATE TABLE IF NOT EXISTS DM_GEOFENCE (
CREATE TABLE IF NOT EXISTS DM_GEOFENCE
(
ID INT NOT NULL AUTO_INCREMENT,
FENCE_NAME VARCHAR(255) NOT NULL,
DESCRIPTION TEXT DEFAULT NULL,
@ -669,7 +708,8 @@ CREATE TABLE IF NOT EXISTS DM_GEOFENCE (
-- END OF DM_GEOFENCE TABLE--
-- DM_GEOFENCE_GROUP_MAPPING TABLE--
CREATE TABLE IF NOT EXISTS DM_GEOFENCE_GROUP_MAPPING (
CREATE TABLE IF NOT EXISTS DM_GEOFENCE_GROUP_MAPPING
(
ID INT NOT NULL AUTO_INCREMENT,
FENCE_ID INT NOT NULL,
GROUP_ID INT NOT NULL,
@ -684,7 +724,8 @@ CREATE TABLE IF NOT EXISTS DM_GEOFENCE_GROUP_MAPPING (
-- DM_DEVICE_EVENT TABLE --
CREATE TABLE IF NOT EXISTS DM_DEVICE_EVENT (
CREATE TABLE IF NOT EXISTS DM_DEVICE_EVENT
(
ID INT NOT NULL AUTO_INCREMENT,
EVENT_SOURCE VARCHAR(100) NOT NULL,
EVENT_LOGIC VARCHAR(100) NOT NULL,
@ -697,7 +738,8 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_EVENT (
-- END OF DM_DEVICE_EVENT TABLE --
-- DM_DEVICE_EVENT_GROUP_MAPPING TABLE--
CREATE TABLE IF NOT EXISTS DM_DEVICE_EVENT_GROUP_MAPPING (
CREATE TABLE IF NOT EXISTS DM_DEVICE_EVENT_GROUP_MAPPING
(
ID INT NOT NULL AUTO_INCREMENT,
EVENT_ID INT NOT NULL,
GROUP_ID INT NOT NULL,
@ -711,7 +753,8 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_EVENT_GROUP_MAPPING (
-- END OF DM_DEVICE_EVENT_GROUP_MAPPING TABLE--
-- DM_GEOFENCE_GROUP_MAPPING TABLE--
CREATE TABLE IF NOT EXISTS DM_GEOFENCE_EVENT_MAPPING (
CREATE TABLE IF NOT EXISTS DM_GEOFENCE_EVENT_MAPPING
(
ID INT NOT NULL AUTO_INCREMENT,
FENCE_ID INT NOT NULL,
EVENT_ID INT NOT NULL,
@ -725,7 +768,8 @@ CREATE TABLE IF NOT EXISTS DM_GEOFENCE_EVENT_MAPPING (
-- END OF DM_GEOFENCE_GROUP_MAPPING TABLE--
-- DM_EXT_GROUP_MAPPING TABLE--
CREATE TABLE IF NOT EXISTS DM_EXT_GROUP_MAPPING (
CREATE TABLE IF NOT EXISTS DM_EXT_GROUP_MAPPING
(
ID INT NOT NULL AUTO_INCREMENT,
TRACCAR_GROUP_ID INT DEFAULT 0,
GROUP_ID INT NOT NULL,
@ -736,7 +780,8 @@ CREATE TABLE IF NOT EXISTS DM_EXT_GROUP_MAPPING (
-- END OF DM_EXT_GROUP_MAPPING TABLE--
-- END OF DM_EXT_DEVICE_MAPPING TABLE--
CREATE TABLE IF NOT EXISTS DM_EXT_DEVICE_MAPPING (
CREATE TABLE IF NOT EXISTS DM_EXT_DEVICE_MAPPING
(
ID INT NOT NULL AUTO_INCREMENT,
TRACCAR_DEVICE_ID INT DEFAULT 0,
DEVICE_ID INT NOT NULL,
@ -765,14 +810,16 @@ CREATE TABLE IF NOT EXISTS DM_EXT_DEVICE_MAPPING (
-- END OF DM_EXT_DEVICE_MAPPING TABLE--
-- END OF DM_EXT_PERMISSION_MAPPING TABLE--
CREATE TABLE IF NOT EXISTS DM_EXT_PERMISSION_MAPPING (
CREATE TABLE IF NOT EXISTS DM_EXT_PERMISSION_MAPPING
(
TRACCAR_DEVICE_ID INT DEFAULT 0,
TRACCAR_USER_ID INT DEFAULT 0
);
-- END OF DM_EXT_PERMISSION_MAPPING TABLE--
-- DYNAMIC TASK TABLES--
CREATE TABLE IF NOT EXISTS DYNAMIC_TASK (
CREATE TABLE IF NOT EXISTS DYNAMIC_TASK
(
DYNAMIC_TASK_ID INTEGER AUTO_INCREMENT NOT NULL,
NAME VARCHAR(300) DEFAULT NULL,
CRON VARCHAR(8000) DEFAULT NULL,
@ -782,7 +829,8 @@ CREATE TABLE IF NOT EXISTS DYNAMIC_TASK (
PRIMARY KEY (DYNAMIC_TASK_ID)
);
CREATE TABLE IF NOT EXISTS DYNAMIC_TASK_PROPERTIES (
CREATE TABLE IF NOT EXISTS DYNAMIC_TASK_PROPERTIES
(
DYNAMIC_TASK_ID INTEGER NOT NULL,
PROPERTY_NAME VARCHAR(100) DEFAULT 0,
PROPERTY_VALUE VARCHAR(100) DEFAULT NULL,
@ -794,7 +842,8 @@ CREATE TABLE IF NOT EXISTS DYNAMIC_TASK_PROPERTIES (
-- END OF DYNAMIC TASK TABLE--
-- DM_DEVICE_SUB_TYPE TABLE--
CREATE TABLE IF NOT EXISTS DM_DEVICE_SUB_TYPE (
CREATE TABLE IF NOT EXISTS DM_DEVICE_SUB_TYPE
(
TENANT_ID INT DEFAULT 0,
SUB_TYPE_ID VARCHAR(45) NOT NULL,
DEVICE_TYPE VARCHAR(25) NOT NULL,
@ -805,8 +854,9 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_SUB_TYPE (
-- END OF DM_DEVICE_SUB_TYPE TABLE--
-- DM_DEVICE_ORGANIZATION TABLE--
CREATE TABLE IF NOT EXISTS DM_DEVICE_ORGANIZATION (
ID INTEGER AUTO_INCREMENT NOT NULL,
CREATE TABLE IF NOT EXISTS DM_DEVICE_ORGANIZATION
(
ID INT NOT NULL AUTO_INCREMENT,
DEVICE_ID INT(11) NOT NULL,
PARENT_DEVICE_ID INT(11) DEFAULT NULL,
LAST_UPDATED_TIMESTAMP TIMESTAMP NOT NULL,

@ -18,8 +18,9 @@
-- Table `DM_DEVICE_ORGANIZATION`
-- -----------------------------------------------------
-- DM_DEVICE_ORGANIZATION TABLE--
CREATE TABLE IF NOT EXISTS DM_DEVICE_ORGANIZATION (
ID INTEGER auto_increment NOT NULL,
ID INT NOT NULL AUTO_INCREMENT,
DEVICE_ID INT(11) NOT NULL,
PARENT_DEVICE_ID INT(11) DEFAULT NULL,
LAST_UPDATED_TIMESTAMP TIMESTAMP NOT NULL,
@ -30,18 +31,16 @@
REFERENCES DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT CHILD_PARENT_COMP_KEY UNIQUE (DEVICE_ID, PARENT_DEVICE_ID)
);
-- END OF DM_DEVICE_ORGANIZATION TABLE--
-- -----------------------------------------------------
-- Sample data for test cases
-- -----------------------------------------------------
INSERT INTO DM_DEVICE_TYPE (ID,NAME,DEVICE_TYPE_META,LAST_UPDATED_TIMESTAMP,PROVIDER_TENANT_ID,SHARED_WITH_ALL_TENANTS)
VALUES (1,'METER','meter',CURRENT_TIMESTAMP(),1,true);
INSERT INTO DM_DEVICE (ID,DESCRIPTION,NAME,DEVICE_TYPE_ID,DEVICE_IDENTIFICATION,LAST_UPDATED_TIMESTAMP,TENANT_ID) VALUES
(1,'test device 1','Meter 01',1,'0001',CURRENT_TIMESTAMP(),1),
(2,'test device 2','Meter 02',1,'0002',CURRENT_TIMESTAMP(),1),
(3,'test device 3','Meter 03',1,'0003',CURRENT_TIMESTAMP(),1),
(4,'test device 4','Meter 04',1,'0004',CURRENT_TIMESTAMP(),1),
-- INSERT INTO DM_DEVICE_ORGANIZATION (DEVICE_ID, PARENT_DEVICE_ID, LAST_UPDATED_TIMESTAMP) VALUES
-- (2,1,CURRENT_TIMESTAMP()),
-- (3,2,CURRENT_TIMESTAMP());
INSERT INTO DM_DEVICE_TYPE (NAME,DEVICE_TYPE_META,LAST_UPDATED_TIMESTAMP,PROVIDER_TENANT_ID,SHARED_WITH_ALL_TENANTS)
VALUES ('METER','meter',CURRENT_TIMESTAMP(),1,true);
INSERT INTO DM_DEVICE (DESCRIPTION,NAME,DEVICE_TYPE_ID,DEVICE_IDENTIFICATION,LAST_UPDATED_TIMESTAMP,TENANT_ID) VALUES
('test device 1','Meter_01',1,'0001',CURRENT_TIMESTAMP(),1),
('test device 2','Meter_02',1,'0002',CURRENT_TIMESTAMP(),1),
('test device 3','Meter_03',1,'0003',CURRENT_TIMESTAMP(),1),
('test device 4','Meter_04',1,'0004',CURRENT_TIMESTAMP(),1);

@ -839,3 +839,18 @@ CREATE TABLE SUB_OPERATION_TEMPLATE (
);
-- END OF SUB_OPERATION_TEMPLATE TABLE--
-- DM_DEVICE_ORGANIZATION TABLE--
CREATE TABLE IF NOT EXISTS DM_DEVICE_ORGANIZATION (
ID INT NOT NULL AUTO_INCREMENT,
DEVICE_ID INT(11) NOT NULL,
PARENT_DEVICE_ID INT(11) DEFAULT NULL,
LAST_UPDATED_TIMESTAMP TIMESTAMP NOT NULL,
PRIMARY KEY (ID),
CONSTRAINT fk_DM_DEVICE_DM_ID FOREIGN KEY (DEVICE_ID)
REFERENCES DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT fk_DM_DEVICE_DM_ID2 FOREIGN KEY (PARENT_DEVICE_ID)
REFERENCES DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT CHILD_PARENT_COMP_KEY UNIQUE (DEVICE_ID, PARENT_DEVICE_ID)
);
-- END OF DM_DEVICE_ORGANIZATION TABLE--

@ -912,3 +912,18 @@ CREATE TABLE SUB_OPERATION_TEMPLATE (
);
-- END SUB_OPERATION_TEMPLATE TABLE--
-- DM_DEVICE_ORGANIZATION TABLE--
CREATE TABLE IF NOT EXISTS DM_DEVICE_ORGANIZATION (
ID INT NOT NULL IDENTITY(1,1),
DEVICE_ID INT NOT NULL,
PARENT_DEVICE_ID INT DEFAULT NULL,
LAST_UPDATED_TIMESTAMP BIGINT NOT NULL,
PRIMARY KEY (ID),
CONSTRAINT fk_DM_DEVICE_DM_ID FOREIGN KEY (DEVICE_ID)
REFERENCES DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT fk_DM_DEVICE_DM_ID2 FOREIGN KEY (PARENT_DEVICE_ID)
REFERENCES DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT CHILD_PARENT_COMP_KEY UNIQUE (DEVICE_ID, PARENT_DEVICE_ID)
);
-- END OF DM_DEVICE_ORGANIZATION TABLE--

@ -907,3 +907,18 @@ CREATE TABLE SUB_OPERATION_TEMPLATE (
) ENGINE=InnoDB;
-- END OF SUB_OPERATION_TEMPLATE TABLE--
-- DM_DEVICE_ORGANIZATION TABLE--
CREATE TABLE IF NOT EXISTS DM_DEVICE_ORGANIZATION (
ID INT NOT NULL AUTO_INCREMENT,
DEVICE_ID INT(11) NOT NULL,
PARENT_DEVICE_ID INT(11) DEFAULT NULL,
LAST_UPDATED_TIMESTAMP TIMESTAMP NOT NULL,
PRIMARY KEY (ID),
CONSTRAINT fk_DM_DEVICE_DM_ID FOREIGN KEY (DEVICE_ID)
REFERENCES DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT fk_DM_DEVICE_DM_ID2 FOREIGN KEY (PARENT_DEVICE_ID)
REFERENCES DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT CHILD_PARENT_COMP_KEY UNIQUE (DEVICE_ID, PARENT_DEVICE_ID)
);
-- END OF DM_DEVICE_ORGANIZATION TABLE--

@ -1191,5 +1191,38 @@ ALTER TABLE SUB_OPERATION_TEMPLATE
-- Generate ID using sequence and trigger
CREATE SEQUENCE SUB_OPERATION_TEMPLATE_seq START WITH 1 INCREMENT BY 1;
/
-- END OF SUB_OPERATION_TEMPLATE TABLE--
-- DM_DEVICE_ORGANIZATION TABLE--
CREATE TABLE IF NOT EXISTS DM_DEVICE_ORGANIZATION (
ID NUMBER(10) NOT NULL,
DEVICE_ID NUMBER(10) NOT NULL,
PARENT_DEVICE_ID NUMBER(10) DEFAULT NULL,
LAST_UPDATED_TIMESTAMP TIMESTAMP(0) NOT NULL,
CONSTRAINT PK_DM_DEVICE_ORGANIZATION PRIMARY KEY (ID),
CONSTRAINT fk_DM_DEVICE_DM_ID FOREIGN KEY (DEVICE_ID)
REFERENCES DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT fk_DM_DEVICE_DM_ID2 FOREIGN KEY (PARENT_DEVICE_ID)
REFERENCES DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT CHILD_PARENT_COMP_KEY UNIQUE (DEVICE_ID, PARENT_DEVICE_ID)
);
/
-- Generate ID using sequence and trigger
CREATE SEQUENCE DM_DEVICE_ORGANIZATION_seq START WITH 1 INCREMENT BY 1 NOCACHE
/
CREATE OR REPLACE TRIGGER DM_DEVICE_ORGANIZATION_seq_tr
BEFORE INSERT
ON DM_DEVICE_ORGANIZATION
REFERENCING NEW AS NEW
FOR EACH ROW
WHEN (NEW.ID IS NULL)
BEGIN
SELECT DM_DEVICE_ORGANIZATION_seq.NEXTVAL
INTO :NEW.ID
FROM DUAL;
END;
/
-- END OF DM_DEVICE_ORGANIZATION TABLE--
)

@ -846,3 +846,19 @@ CREATE TABLE DM_DEVICE_CERTIFICATE (
PRIMARY KEY (ID)
)
-- DM_DEVICE_ORGANIZATION TABLE--
CREATE SEQUENCE DM_DEVICE_ORGANIZATION_seq;
CREATE TABLE IF NOT EXISTS DM_DEVICE_ORGANIZATION (
ID INTEGER DEFAULT NEXTVAL ('DM_DEVICE_ORGANIZATION_seq') NOT NULL,
DEVICE_ID INTEGER NOT NULL,
PARENT_DEVICE_ID INTEGER DEFAULT NULL,
LAST_UPDATED_TIMESTAMP TIMESTAMP(0) NOT NULL NOT NULL,
PRIMARY KEY (ID),
CONSTRAINT fk_DM_DEVICE_DM_ID FOREIGN KEY (DEVICE_ID)
REFERENCES DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT fk_DM_DEVICE_DM_ID2 FOREIGN KEY (PARENT_DEVICE_ID)
REFERENCES DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT CHILD_PARENT_COMP_KEY UNIQUE (DEVICE_ID, PARENT_DEVICE_ID)
);
-- END OF DM_DEVICE_ORGANIZATION TABLE--

Loading…
Cancel
Save