-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1e23a51
commit b6ec097
Showing
11 changed files
with
173 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
arches/app/models/migrations/11613_nodegroup_grouping_node.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# Generated by Django 5.1.3 on 2024-11-19 09:29 | ||
|
||
import django.db.models.deletion | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("models", "10437_node_alias_not_null"), | ||
] | ||
|
||
def add_grouping_node(apps, schema_editor): | ||
NodeGroup = apps.get_model("models", "NodeGroup") | ||
nodegroups_with_nodes = NodeGroup.objects.filter(node__gt=0).distinct() | ||
for nodegroup in nodegroups_with_nodes: | ||
nodegroup.grouping_node_id = nodegroup.pk | ||
NodeGroup.objects.bulk_update(nodegroups_with_nodes, ["grouping_node_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["grouping_node_id"] = node_dict["nodegroup_id"] | ||
PublishedGraph.objects.bulk_update(published_graphs, ["serialized_graph"]) | ||
|
||
def remove_grouping_node(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["nodegroups"]: | ||
node_dict.pop("grouping_node_id", None) | ||
PublishedGraph.objects.bulk_update(published_graphs, ["serialized_graph"]) | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="nodegroup", | ||
name="grouping_node", | ||
field=models.OneToOneField( | ||
blank=True, | ||
db_column="groupingnodeid", | ||
null=True, | ||
on_delete=django.db.models.deletion.SET_NULL, | ||
related_name="grouping_node_nodegroup", | ||
to="models.node", | ||
), | ||
), | ||
migrations.AlterField( | ||
model_name="nodegroup", | ||
name="cardinality", | ||
field=models.CharField( | ||
blank=True, choices=[("1", "1"), ("n", "n")], default="1", max_length=1 | ||
), | ||
), | ||
migrations.AlterField( | ||
model_name="nodegroup", | ||
name="parentnodegroup", | ||
field=models.ForeignKey( | ||
blank=True, | ||
db_column="parentnodegroupid", | ||
null=True, | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name="children", | ||
related_query_name="child", | ||
to="models.nodegroup", | ||
), | ||
), | ||
migrations.RunPython(add_grouping_node, remove_grouping_node), | ||
] |
33 changes: 33 additions & 0 deletions
33
arches/app/models/migrations/11613_nodegroup_grouping_node_constraints.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Generated by Django 5.1.3 on 2024-11-19 09:33 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("models", "11613_nodegroup_grouping_node"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddConstraint( | ||
model_name="node", | ||
constraint=models.CheckConstraint( | ||
condition=models.Q( | ||
("istopnode", True), ("nodegroup__isnull", False), _connector="OR" | ||
), | ||
name="has_nodegroup_or_istopnode", | ||
), | ||
), | ||
migrations.AddConstraint( | ||
model_name="nodegroup", | ||
constraint=models.CheckConstraint( | ||
condition=models.Q( | ||
("grouping_node", models.F("pk")), | ||
("grouping_node__isnull", True), | ||
_connector="OR", | ||
), | ||
name="grouping_node_matches_pk_or_null", | ||
), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters