Skip to content

Commit

Permalink
Added rule to consider migration from ascendant entities and 3 entity
Browse files Browse the repository at this point in the history
relationships
  • Loading branch information
suarezgpablo committed Nov 22, 2024
1 parent c573542 commit ffd7917
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<MigrationTable xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns="DataMigration" name="entity_view">
<migcol>
<migcol multipleMigration="true">
<ColTo Data="dev_type" Key="tenant_id , customer_id" DataTable="entity_view"/>
<ColFrom Data="type" Key="tenant_id , customer_id" DataTable="device"/>
</migcol>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<MigrationTable xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns="DataMigration" name="entity_view2_old">
<migcol>
<migcol multipleMigration="true">
<ColTo Data="dev_type" Key="tenant_id , customer_id" DataTable="entity_view2_old" NewTableName="entity_view2"/>
<ColFrom Data="type" Key="tenant_id , customer_id" DataTable="device"/>
</migcol>
Expand Down
3 changes: 1 addition & 2 deletions modevo-transform/dat/inp/ThingsBoardCM.xmi
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

<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" cardinality1="1" cardinality2="n"/>
<Relationship xmi:id="r5" name ="relation4" entity1="e2" 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 @@ -23,6 +23,8 @@
<eStructuralFeatures xsi:type="ecore:EAttribute" name="cardinality2" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="attribute" upperBound="-1"
eType="#//Attribute" containment="true"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="cardinality3" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="entity3" eType="#//Entity"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="WeakEntity" eSuperTypes="#//Entity"/>
</ecore:EPackage>
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<eStructuralFeatures xsi:type="ecore:EAttribute" name="Description" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="ColToSplit" lowerBound="1"
upperBound="-1" eType="#//To" containment="true"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="multipleMigration" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Criteria">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="Rule" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ lazy rule MigCol {
->select (c | c.nameAttribute = r.nameAttribute and c.nameEntity = r.nameEntity and thisModule.keyInTable(c.tableColumn, keyColumnToColumn)).first();
--Gets key columns
colKeyFromVariable: Sequence (Schema!Column) = colFromVariable.tableColumn.Column -> select (c | c.equivalentColumnInSequenceTables(keyColumnToColumn));

ascendantsUsed : Boolean = thisModule.ascendentsUsed (r.tab.tableFromLM().Column, thisModule.extractEntityByName (r.nameEntity), r.tab.tableFromLM());
}
to
add: DataMigration!MigrationCol ( --for each new column
multipleMigration <- ascendantsUsed,
ColTo <- thisModule.columnTo (r, keyColumnToColumn),
ColFrom <- thisModule.columnFrom (colKeyFromVariable, colFromVariable)
)
Expand Down Expand Up @@ -81,10 +84,31 @@ helper def: typeKey (columns: Sequence (Schema!Column), entity: ConceptualModel!
if (not (table.descendentsEntityInTable(entity).isEmpty()))
then thisModule.keyEntitiesSequence (columns, table.descendentsEntityInTable(entity))
else
thisModule.keyEntitiesSequence (columns, table.NMEntities(entity))
if (not (table.NMEntities(entity).isEmpty()))
then thisModule.keyEntitiesSequence (columns, table.NMEntities(entity))
else
thisModule.keyEntitiesSequence (columns, table.ascendantsEntityInTable(entity))
endif
endif
endif;

---Copy of typeKey to know if "thisModule.keyEntitiesSequence (columns, table.ascendantsEntityInTable(entity)" was used
helper def: ascendentsUsed (columns: Sequence (Schema!Column), entity: ConceptualModel!Entity, table: Schema!Table): Boolean =
if (thisModule.isKeyEntityInColumns (columns, entity))
then false
else
if (not (table.descendentsEntityInTable(entity).isEmpty()))
then false
else
if (not (table.NMEntities(entity).isEmpty()))
then false
else
true
endif
endif
endif;


---Returns true if in given columns there are columns associated to the key attributes of entity
helper def: isKeyEntityInColumns (columns: Sequence (Schema!Column), entity: ConceptualModel!Entity): Boolean =
let keyAttributes : Sequence (ConceptualModel!Attribute) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,13 @@ helper context ConceptualModel!Entity def: entitiesRelatedAscendancy (): Sequenc

---Returns true if the given entity is detail of e
helper context ConceptualModel!Entity def: isEntityAscendancy (e: ConceptualModel!Entity): Boolean =
if (ConceptualModel!Relationship.allInstancesFrom('CM')->any (r | (r.entity1 = e and r.entity2 = self and r.cardinality1 = 'n' and r.cardinality2 = '1') or (r.entity1 = self and r.entity2 = e and r.cardinality1 = '1' and r.cardinality2 = 'n')).oclIsUndefined())
if (ConceptualModel!Relationship.allInstancesFrom('CM')->any (r | (r.entity1 = e and r.entity2 = self and r.cardinality1 = 'n' and r.cardinality2 = '1')
or (r.entity1 = self and r.entity2 = e and r.cardinality1 = '1' and r.cardinality2 = 'n')
or (r.entity1 = e and r.entity3 = self and r.cardinality1 = 'n' and r.cardinality3 = '1')
or (r.entity1 = self and r.entity3 = e and r.cardinality1 = '1' and r.cardinality3 = 'n')
or (r.entity2 = e and r.entity3 = self and r.cardinality2 = 'n' and r.cardinality3 = '1')
or (r.entity2 = self and r.entity3 = e and r.cardinality2 = '1' and r.cardinality3 = 'n')
).oclIsUndefined())
then
false
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ helper context Schema!Table def: EntitiesInTable (): Sequence (ConceptualModel!E

---Obtains the entities that are in the self table that are also ascendants of e
helper context Schema!Table def: ascendantsEntityInTable (e: ConceptualModel!Entity): Sequence (ConceptualModel!Entity) =
e.entitiesRelatedAscendancy().intersection(self.EntitiesInTable());
e.entitiesRelatedAscendancy()->select (entity | self.EntitiesInTable().includes(entity));

---Obtains the key columns of a given table.
helper def: keyColumnsNewTable (table : SchemaEvolution!Table): Sequence (SchemaEvolution!Column) =
Expand Down

0 comments on commit ffd7917

Please sign in to comment.