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 15, 2024
1 parent d6a713b commit 22071b7
Show file tree
Hide file tree
Showing 5 changed files with 163 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -181,26 +181,29 @@ 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);

Check failure on line 184 in modevo-consistency/src/test/java/test4giis/consistency/TestCheckConsistency.java

View workflow job for this annotation

GitHub Actions / verify-result-consistency

TestCheckConsistency.testThingsBoardV11NewColumnNonKey

java.sql.SQLSyntaxErrorException: Unknown database 'thingsboard2'
Raw output
giis.modevo.migration.script.ScriptException: java.sql.SQLSyntaxErrorException: Unknown database 'thingsboard2'
	at giis.modevo.consistency.OracleConnection.connect(OracleConnection.java:42)
	at test4giis.consistency.TestCheckConsistency.migrateSqlToCassandra(TestCheckConsistency.java:267)
	at test4giis.consistency.TestCheckConsistency.setUpCassandraDatabase(TestCheckConsistency.java:235)
	at test4giis.consistency.TestCheckConsistency.testConsistency(TestCheckConsistency.java:216)
	at test4giis.consistency.TestCheckConsistency.testThingsBoardV11NewColumnNonKey(TestCheckConsistency.java:184)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:569)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:61)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
	at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
	at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
	at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:316)
	at org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:240)
	at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:214)
	at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:155)
	at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:385)
	at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:162)
	at org.apache.maven.surefire.booter.ForkedBooter.run(ForkedBooter.java:507)
	at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:495)
Caused by: java.sql.SQLSyntaxErrorException: Unknown database 'thingsboard2'
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:121)
	at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
	at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:825)
	at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:446)
	at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:239)
	at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:188)
	at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:681)
	at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:252)
	at giis.modevo.consistency.OracleConnection.connect(OracleConnection.java:40)
	... 34 more
}
@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.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("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 22071b7

Please sign in to comment.