Skip to content

Commit

Permalink
fix thingsboard sql database
Browse files Browse the repository at this point in the history
  • Loading branch information
suarezgpablo committed Dec 16, 2024
1 parent 98f30c7 commit 997ea12
Show file tree
Hide file tree
Showing 6 changed files with 162 additions and 29 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ jobs:
docker exec -i test-mysql sh -c "exec mysql -uroot -prootpassword" < ./setup/minds.sql
docker exec -i test-mysql sh -c "exec mysql -uroot -prootpassword" < ./setup/wire.sql
docker exec -i test-mysql sh -c "exec mysql -uroot -prootpassword" < ./setup/thingsboard.sql
docker exec -i test-mysql sh -c "exec mysql -uroot -prootpassword" < ./setup/thingsboard2.sql
- name: Initialize Cassandra database
run: |
docker run --name test-cassandra -d -p 9042:9042 \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,26 +181,27 @@ public void testThingsBoardV11NewColumnNonKey() throws IOException {
projectionAfterEvo.put("device", "SELECT device.id as id, tenant.ten_id as tenant_id, customer.cus_id as customer_id, device.dev_name as name, device.dev_type as type FROM device INNER JOIN customer ON customer.iddevice = device.id INNER JOIN tenant ON tenant.iddevice = device.id ORDER BY device.id DESC, tenant_id DESC, customer_ID DESC;");
projectionBeforeEvo.put("entity_view", "SELECT entity.id as id, tenant.ten_id as tenant_id, customer.cus_id as customer_id, entity.name as name, entity.type as type FROM device INNER JOIN customer ON customer.iddevice = device.id INNER JOIN tenant ON tenant.iddevice = device.id INNER JOIN entity ON (customer.identity = entity.id AND tenant.identity = entity.id);");
projectionAfterEvo.put("entity_view", "SELECT entity.id as id, tenant.ten_id as tenant_id, customer.cus_id as customer_id, device.dev_type as dev_type, entity.name as name, entity.type as type FROM device INNER JOIN customer ON customer.iddevice = device.id INNER JOIN tenant ON tenant.iddevice = device.id INNER JOIN entity ON (customer.identity = entity.id AND tenant.identity = entity.id) ORDER BY entity.id DESC;");
testConsistency(name.getMethodName(), projectionAfterEvo, "thingsboard", projectionBeforeEvo);
testConsistency(name.getMethodName(), projectionAfterEvo, "thingsboard2", projectionBeforeEvo);
}
@Test
public void testThingsBoardV12NewColumnPK() throws IOException {
Map<String, String> projectionAfterEvo = new HashMap<String, String>();
Map<String, String> projectionBeforeEvo = new HashMap<String, String>();
projectionBeforeEvo.put("device", "SELECT device.id as id, tenant.ten_id as tenant_id, customer.cus_id as customer_id, device.dev_name as name, device.dev_type as type FROM device INNER JOIN customer ON customer.iddevice = device.id INNER JOIN tenant ON tenant.iddevice = device.id;");
projectionAfterEvo.put("device", "SELECT device.id as id, tenant.ten_id as tenant_id, customer.cus_id as customer_id, device.dev_name as name, device.dev_type as type FROM device INNER JOIN customer ON customer.iddevice = device.id INNER JOIN tenant ON tenant.iddevice = device.id ORDER BY device.id DESC, tenant_id DESC, customer_ID DESC;");
projectionBeforeEvo.put("entity_view2_old", "SELECT entity.id as id, tenant.ten_id as tenant_id, customer.cus_id as customer_id, entity.name as name, entity.type as type FROM device INNER JOIN customer ON customer.iddevice = device.id INNER JOIN tenant ON tenant.iddevice = device.id INNER JOIN entity ON (customer.identity = entity.id AND tenant.identity = entity.id);");
projectionAfterEvo.put("entity_view2", "SELECT entity.id as id, tenant.ten_id as tenant_id, customer.cus_id as customer_id, device.dev_type as dev_type, entity.name as name, entity.type as type FROM device INNER JOIN customer ON customer.iddevice = device.id INNER JOIN tenant ON tenant.iddevice = device.id INNER JOIN entity ON (customer.identity = entity.id AND tenant.identity = entity.id) ORDER BY entity.id DESC;");
projectionBeforeEvo.put("device", "SELECT device.id as id, tenant.ten_id as tenant_id, customer.cus_id as customer_id, device.dev_name as name, device.dev_type as type FROM device INNER JOIN customer ON customer.cus_id = device.idcustomer INNER JOIN tenant ON tenant.ten_id = device.idtenant;");
projectionAfterEvo.put("device", "SELECT device.id as id, tenant.ten_id as tenant_id, customer.cus_id as customer_id, device.dev_name as name, device.dev_type as type FROM device INNER JOIN customer ON customer.cus_id = device.idcustomer INNER JOIN tenant ON tenant.ten_id = device.idtenant ORDER BY device.id DESC, tenant_id DESC, customer_ID DESC;");
projectionBeforeEvo.put("entity_view2_old", "SELECT entity.id as id, tenant.ten_id as tenant_id, customer.cus_id as customer_id, entity.name as name, entity.type as type FROM device INNER JOIN customer ON customer.cus_id = device.idcustomer INNER JOIN tenant ON tenant.ten_id = device.idtenant INNER JOIN entity ON (customer.identity = entity.id AND tenant.identity = entity.id);");
projectionAfterEvo.put("entity_view2", "SELECT entity.id as id, tenant.ten_id as tenant_id, customer.cus_id as customer_id, device.dev_type as dev_type, entity.name as name, entity.type as type FROM device INNER JOIN customer ON customer.cus_id = device.idcustomer INNER JOIN tenant ON tenant.ten_id = device.idtenant INNER JOIN entity ON (customer.identity = entity.id AND tenant.identity = entity.id) ORDER BY id DESC, tenant_id DESC, customer_id DESC, dev_type DESC;");
testConsistency(name.getMethodName(), projectionAfterEvo, "thingsboard", projectionBeforeEvo);
}
@Test
public void testThingsBoardV13NewColumnKeyInTable() throws IOException {
Map<String, String> projectionAfterEvo = new HashMap<String, String>();
Map<String, String> projectionBeforeEvo = new HashMap<String, String>();
projectionBeforeEvo.put("device", "SELECT device.id as id, tenant.ten_id as tenant_id, customer.cus_id as customer_id, device.dev_name as name, device.dev_type as type FROM device INNER JOIN customer ON customer.iddevice = device.id INNER JOIN tenant ON tenant.iddevice = device.id;");
projectionAfterEvo.put("device", "SELECT device.id as id, tenant.ten_id as tenant_id, customer.cus_id as customer_id, device.dev_name as name, device.dev_type as type FROM device INNER JOIN customer ON customer.iddevice = device.id INNER JOIN tenant ON tenant.iddevice = device.id ORDER BY device.id DESC, tenant_id DESC, customer_ID DESC;");
projectionBeforeEvo.put("entity_view_devpk", "SELECT entity.id as id, tenant.ten_id as tenant_id, customer.cus_id as customer_id, device.id as device_id, entity.name as name, entity.type as type FROM device INNER JOIN customer ON customer.iddevice = device.id INNER JOIN tenant ON tenant.iddevice = device.id INNER JOIN entity ON (customer.identity = entity.id AND tenant.identity = entity.id);");
projectionAfterEvo.put("entity_view_devpk", "SELECT entity.id as id, tenant.ten_id as tenant_id, customer.cus_id as customer_id, device.id as device_id, device.dev_type as dev_type, entity.name as name, entity.type as type FROM device INNER JOIN customer ON customer.iddevice = device.id INNER JOIN tenant ON tenant.iddevice = device.id INNER JOIN entity ON (customer.identity = entity.id AND tenant.identity = entity.id) ORDER BY entity.id DESC;");
projectionBeforeEvo.put("device", "SELECT device.id as id, tenant.ten_id as tenant_id, customer.cus_id as customer_id, device.dev_name as name, device.dev_type as type FROM device INNER JOIN customer ON customer.cus_id = device.idcustomer INNER JOIN tenant ON tenant.ten_id = device.idtenant;");
projectionAfterEvo.put("device", "SELECT device.id as id, tenant.ten_id as tenant_id, customer.cus_id as customer_id, device.dev_name as name, device.dev_type as type FROM device INNER JOIN customer ON customer.cus_id = device.idcustomer INNER JOIN tenant ON tenant.ten_id = device.idtenant ORDER BY device.id DESC, tenant_id DESC, customer_ID DESC;");
projectionBeforeEvo.put("entity_view_devpk", "SELECT entity.id as id, tenant.ten_id as tenant_id, customer.cus_id as customer_id, device.id as device_id, entity.name as name, entity.type as type FROM device INNER JOIN customer ON customer.cus_id = device.idcustomer INNER JOIN tenant ON tenant.ten_id = device.idtenant INNER JOIN entity ON (customer.identity = entity.id AND tenant.identity = entity.id);");
projectionAfterEvo.put("entity_view_devpk", "SELECT entity.id as id, tenant.ten_id as tenant_id, customer.cus_id as customer_id, device.id as device_id, device.dev_type as dev_type, entity.name as name, entity.type as type FROM device INNER JOIN customer ON customer.cus_id = device.idcustomer INNER JOIN tenant ON tenant.ten_id = device.idtenant INNER JOIN entity ON (customer.identity = entity.id AND tenant.identity = entity.id) ORDER BY id DESC, tenant_id DESC, customer_id DESC, device_id DESC, dev_type DESC;");

testConsistency(name.getMethodName(), projectionAfterEvo, "thingsboard", projectionBeforeEvo);
}
/**
Expand Down
6 changes: 0 additions & 6 deletions modevo-transform/dat/inp/ThingsBoardCM.xmi
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,15 @@
<Attribute xmi:id="a1" name = "id" entity='e1' isUnique="true"/>
<Attribute xmi:id="a2" name = "name" entity='e1' isUnique="false"/>
<Attribute xmi:id="a3" name = "type" entity='e1' isUnique="false"/>

<Entity xmi:id="e2" name="device"/>
<Attribute xmi:id="a4" name = "dev_id" entity='e2' isUnique="true"/>
<Attribute xmi:id="a5" name = "dev_name" entity='e2' isUnique="false"/>
<Attribute xmi:id="a6" name = "dev_type" entity='e2' isUnique="false"/>

<Entity xmi:id="e3" name="tenant"/>
<Attribute xmi:id="a7" name = "ten_id" entity='e3' isUnique="true"/>

<Entity xmi:id="e4" name="customer"/>
<Attribute xmi:id="a8" name = "cus_id" entity='e4' isUnique="true"/>


<Relationship xmi:id="r2" name ="relation1" entity1="e1" entity2="e3" cardinality1="1" cardinality2="n" />
<Relationship xmi:id="r3" name ="relation2" entity1="e1" entity2="e4" cardinality1="1" cardinality2="n"/>
<Relationship xmi:id="r4" name ="relation3" entity1="e2" entity2="e3" entity3="e4" cardinality1="n" cardinality2="1" cardinality3="1"/>

</xmi:XMI>
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="SchemaEvolution">
<eClassifiers xsi:type="ecore:EClass" name="NewColumn">
<eStructuralFeatures xsi:type="ecore:EReference" name="columns" upperBound="-1"
eType="#//Column"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="columns" lowerBound="1"
upperBound="-1" eType="#//Column"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="table" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Table">
Expand Down
24 changes: 12 additions & 12 deletions setup/thingsboard.sql

Large diffs are not rendered by default.

Loading

0 comments on commit 997ea12

Please sign in to comment.