Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
suarezgpablo committed Dec 2, 2024
1 parent 896bc48 commit f4fea59
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 16 deletions.
4 changes: 2 additions & 2 deletions modevo-script/dat/bmk/testCustomV9RemovePK-script.cql
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
FOR $1,$2,$3 = SELECT idAuthor, idBook, title FROM table1BeforeChange
INSERT INTO table1(idAuthor, idBook, title) VALUES ($1, $2, $3);
FOR $1,$2 = SELECT idAuthor, idBook FROM table1BeforeChange
INSERT INTO table1(idAuthor, idBook) VALUES ($1, $2);
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ private Script migrationNewTableAll(Schema schema, SchemaEvolution se, Migration
//Includes the information required to obtain data from column 'c'
s.addColumnSearch (schema, se, nameTable, c);
Column target = mu.findColumn(schema, se, mc.getMigrateTo().getTable(), mc.getMigrateTo().getData());

//Includes the information required to insert the data queries by 's' in an iteration into 'c'
insert.addColumnValue (c, s, null, target);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,4 @@
<MigrateTo Data="idBook" DataTable="table1"/>
<MigrateFrom Data="idBook" DataTable="table1BeforeChange"/>
</migcol>
<migcol>
<MigrateTo Data="title" DataTable="table1"/>
<MigrateFrom Data="title" DataTable="table1BeforeChange"/>
</migcol>
</MigrationTable>
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.w3c.dom.Node;

import giis.modevo.model.schema.Column;
import giis.modevo.model.schema.Schema;
import giis.modevo.model.schema.Table;
import lombok.Getter;
import lombok.Setter;
Expand All @@ -31,14 +32,22 @@ public RemovePK(Column c, Table t, String namePreviousTable) {
}

@Override
protected List<SchemaChange> changesSchemaModel (Node node) {
protected List<SchemaChange> changesSchemaModel (Node node, Schema sc) {
List<SchemaChange> changes = new ArrayList<>();
Element elementCopy = (Element) node;
String table = elementCopy.getAttribute(TABLE);
String columnRemoved = elementCopy.getAttribute("columnRemoved");
String previousTable = elementCopy.getAttribute("previous");
Column c = new Column(columnRemoved);
Table t = new Table(table);
Table previousTableObject = sc.getTable(previousTable);
for (Column preColumn : previousTableObject.getColumns()) {
if (!preColumn.getName().equalsIgnoreCase(columnRemoved)) {
Column newColumn = new Column (preColumn);
newColumn.setNameTable(table);
t.getColumns().add(newColumn);
}
}
RemovePK rp = new RemovePK(c, t, previousTable);
changes.add(rp);
return changes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.w3c.dom.NodeList;

import giis.modevo.model.schema.Column;
import giis.modevo.model.schema.Schema;
import giis.modevo.model.schema.Table;
import lombok.Getter;
import lombok.Setter;
Expand Down Expand Up @@ -109,5 +110,9 @@ protected List<SchemaChange> changesSchemaModel(NodeList list, Element element)
protected List<SchemaChange> changesSchemaModel (Node node) {
throw new UnsupportedOperationException (ERROR_STOREINFO);
}

protected List<SchemaChange> changesSchemaModel(Node node, Schema sc) {
throw new UnsupportedOperationException (ERROR_STOREINFO);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.w3c.dom.NodeList;

import giis.modevo.model.DocumentReader;
import giis.modevo.model.schema.Schema;
import giis.modevo.model.schema.Table;
import lombok.Getter;
import lombok.Setter;
Expand Down Expand Up @@ -57,8 +58,9 @@ public Table getTable(String name) {
/**
* Creates and returns an object that stores in a Java object the content of the
* schema evolution model whose path is passed as an argument
* @param sc
*/
public SchemaEvolution readSchemaEvolutionModel(String pathSchemaEvolutionModel) {
public SchemaEvolution readSchemaEvolutionModel(String pathSchemaEvolutionModel, Schema sc) {
SchemaEvolution se = new SchemaEvolution();
Document doc = new DocumentReader().readDocumentGeneric(pathSchemaEvolutionModel);
NodeList xmi = doc.getElementsByTagName("xmi:XMI");
Expand Down Expand Up @@ -94,7 +96,7 @@ public SchemaEvolution readSchemaEvolutionModel(String pathSchemaEvolutionModel)
se.getChanges().addAll(new MergeColumn().changesSchemaModel(list, node));
} else if (nameElement.equalsIgnoreCase("RemovePK")) {
log.info ("New Remove PK schema modification");
se.getChanges().addAll(new RemovePK().changesSchemaModel(node));
se.getChanges().addAll(new RemovePK().changesSchemaModel(node, sc));
}
}
return se;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public ModelObjects createDataMigrationModelAndScript(String schemaModelPath, St
SchemaEvolution se = new SchemaEvolution();
DataMigration dm = new DataMigration ();
sc = sc.loadSchemaIntoApp(schemaModelPath);
se = se.readSchemaEvolutionModel(schemaEvolutionModelPath);
se = se.readSchemaEvolutionModel(schemaEvolutionModelPath, sc);
dm = dm.readDataMigrationModel(dataMigrationModelPath, se, sc);
return new ModelObjects(sc, se, dm);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
<eStructuralFeatures xsi:type="ecore:EAttribute" name="column" lowerBound="1"
eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="previous" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="columnRemoved" lowerBound="1"
eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="RemoveTable">
<eStructuralFeatures xsi:type="ecore:EReference" name="remove" eType="#//Table"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,33 @@ rule removePK {
to
d: DataMigration!MigrationTable(
name<- j.table,
migcol <- tableTarget.Column -> collect (c | thisModule.columnMigRemovePK(c, tableTarget, j.previous))
migcol <- tableTarget.Column -> select (c |c.name <> j.columnRemoved) -> collect (c | thisModule.columnMigRemovePK(c, tableTarget, j.previous, j.table))
)
}
---Details migration for a single column of a copied table
lazy rule columnMigRemovePK{
from
column: Schema!Column,
tableTarget: Schema!Table,
previous: String
previous: String,
nameCurrent: String

to
add: DataMigration!MigrationCol ( --for each new column
MigrateTo <- thisModule.columnToRemovePKTable (tableTarget, column),
MigrateTo <- thisModule.columnToRemovePKTable (tableTarget, column, nameCurrent),
MigrateFrom <- thisModule.columnCopyTable (previous, column)
)
}
---Defines migration to a table of the given column
lazy rule columnToRemovePKTable {
from
tableTarget: Schema!Table,
r: Schema!Column
r: Schema!Column,
nameCurrent: String
to
MigrateTo: DataMigration!Target (
Data<- r.name,
DataTable <- tableTarget.name
DataTable <- nameCurrent
)
}
---Defines migration from a table of the given column
Expand Down

0 comments on commit f4fea59

Please sign in to comment.