updateRelations method
Implementation
@visibleForTesting
Future<void> updateRelations(Relation rel) async {
if (rel.tableType == SatRelation_RelationType.TABLE) {
// this relation may be for a newly created table
// or for a column that was added to an existing table
final tableName = rel.table;
if (relations[tableName] == null) {
int id = 0;
// generate an id for the new relation as (the highest existing id) + 1
// TODO: why not just use the relation.id coming from pg?
for (final r in relations.values) {
if (r.id > id) {
id = r.id;
}
}
final relation = rel.copyWith(
id: id + 1,
);
relations[tableName] = relation;
} else {
// the relation is for an existing table
// update the information but keep the same ID
final id = relations[tableName]!.id;
final relation = rel.copyWith(id: id);
relations[tableName] = relation;
}
}
}