Skip to content

Commit

Permalink
Propagate new field to serialized graphs re #11613
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtylerwalls committed Nov 14, 2024
1 parent 2ce4baf commit 41e267e
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion arches/app/models/migrations/11613_node_nodegroup_root.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@ def set_nodegroup_root(apps, schema_editor):
node.nodegroup_root_id = node.nodegroup_id
Node.objects.bulk_update(all_but_top_nodes, ["nodegroup_root_id"])

PublishedGraph = apps.get_model("models", "PublishedGraph")
published_graphs = PublishedGraph.objects.all()
for published_graph in published_graphs:
for node_dict in published_graph.serialized_graph["nodes"]:
node_dict["nodegroup_root_id"] = node_dict["nodegroup_id"]
PublishedGraph.objects.bulk_update(published_graphs, ["serialized_graph"])

def remove_nodegroup_root(apps, schema_editor):
PublishedGraph = apps.get_model("models", "PublishedGraph")
published_graphs = PublishedGraph.objects.all()
for published_graph in published_graphs:
for node_dict in published_graph.serialized_graph["nodes"]:
node_dict.pop("nodegroup_root_id", None)
PublishedGraph.objects.bulk_update(published_graphs, ["serialized_graph"])

operations = [
migrations.AddField(
model_name="node",
Expand All @@ -31,5 +46,5 @@ def set_nodegroup_root(apps, schema_editor):
to="models.node",
),
),
migrations.RunPython(set_nodegroup_root, migrations.RunPython.noop),
migrations.RunPython(set_nodegroup_root, remove_nodegroup_root),
]

0 comments on commit 41e267e

Please sign in to comment.