Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include a nodegroup's graph as nodegroup.graphid #11397

Draft
wants to merge 11 commits into
base: dev/8.0.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions arches/app/models/migrations/11396_nodegroup_graph.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Generated by Django 4.2.15 on 2024-08-23 16:20

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
("models", "9053_add_future_graphs"),
]

sql = """
UPDATE node_groups
SET graphid = sub.graphid
FROM (
SELECT DISTINCT ng.nodegroupid, n.graphid
FROM nodes n
JOIN node_groups ng ON n.nodegroupid = ng.nodegroupid
) AS sub
WHERE node_groups.nodegroupid = sub.nodegroupid;
"""

reverse_sql = """"""

operations = [
migrations.AddField(
model_name="nodegroup",
name="graph",
field=models.ForeignKey(
blank=True,
db_column="graphid",
null=True,
on_delete=django.db.models.deletion.CASCADE,
to="models.graphmodel",
),
),
migrations.RunSQL(
sql,
reverse_sql,
),
]
2 changes: 1 addition & 1 deletion arches/app/models/migrations/7787_relational_data_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ class Migration(migrations.Migration):
join node_groups g on g.nodegroupid = n.nodegroupid
where n.nodeid = n.nodegroupid
and g.parentnodegroupid is null
and graphid = model_id
and n.graphid = model_id
loop
perform __arches_create_branch_views(node.nodeid, schema_name, '');
end loop;
Expand Down
6 changes: 3 additions & 3 deletions arches/app/models/migrations/8009_etlmodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@
(select alias from nodes where nodeid = nodegroup_id) as path,
cardinality
FROM
(SELECT ng.nodegroupid, ng.parentnodegroupid, alias, name, cardinality, graphid FROM node_groups ng
(SELECT ng.nodegroupid, ng.parentnodegroupid, n.alias, n.name, ng.cardinality, n.graphid FROM node_groups ng
INNER JOIN nodes n ON ng.nodegroupid = n.nodeid
ORDER by ng.nodegroupid) AS root
WHERE nodegroupid = nodegroup_id
Expand All @@ -190,7 +190,7 @@
path || ' - ' || parent.alias,
parent.cardinality
FROM
(SELECT ng.nodegroupid, ng.parentnodegroupid, alias, name, cardinality, graphid FROM node_groups ng
(SELECT ng.nodegroupid, ng.parentnodegroupid, n.alias, n.name, ng.cardinality, n.graphid FROM node_groups ng
INNER JOIN nodes n ON ng.nodegroupid = n.nodeid
ORDER by ng.nodegroupid) AS parent
INNER JOIN nodegroup_tree nt ON nt.nodegroupid = parent.parentnodegroupid
Expand All @@ -208,7 +208,7 @@
DECLARE
_nodegroupid uuid;
BEGIN
FOR _nodegroupid IN select ng.nodegroupid from node_groups ng join nodes n on ng.nodegroupid = nodeid where graphid = graph_id and ng.parentnodegroupid is null
FOR _nodegroupid IN select ng.nodegroupid from node_groups ng join nodes n on ng.nodegroupid = nodeid where n.graphid = graph_id and ng.parentnodegroupid is null
LOOP
RETURN QUERY SELECT _nodegroupid, * FROM __get_nodegroup_tree(_nodegroupid);
END LOOP;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class Migration(migrations.Migration):
join node_groups g on g.nodegroupid = n.nodegroupid
where n.nodeid = n.nodegroupid
and g.parentnodegroupid is null
and graphid = model_id
and n.graphid = model_id
loop
perform __arches_create_branch_views(node.nodeid, schema_name, '');
end loop;
Expand Down Expand Up @@ -281,7 +281,7 @@ class Migration(migrations.Migration):
join node_groups g on g.nodegroupid = n.nodegroupid
where n.nodeid = n.nodegroupid
and g.parentnodegroupid is null
and graphid = model_id
and n.graphid = model_id
loop
perform __arches_create_branch_views(node.nodeid, schema_name, '');
end loop;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ class Migration(migrations.Migration):
join node_groups g on g.nodegroupid = n.nodegroupid
where n.nodeid = n.nodegroupid
and g.parentnodegroupid is null
and graphid = model_id
and n.graphid = model_id
loop
perform __arches_create_branch_views(node.nodeid, schema_name, '');
end loop;
Expand Down
3 changes: 3 additions & 0 deletions arches/app/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,9 @@ class NodeGroup(models.Model):
null=True,
on_delete=models.CASCADE,
) # Allows nodegroups within nodegroups
graph = models.ForeignKey(
GraphModel, db_column="graphid", blank=True, null=True, on_delete=models.CASCADE
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this blank=False in order to add some friction?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, null=True doesn't really gel with on_delete=cascade, so if it's only here to support preexisting cruft data, and we already have a major version bump, maybe we just add a command to manage.py validate that deletes cruft nodegroups, and say you have to run that fix before upgrading to 8? WDYT?

)

def __init__(self, *args, **kwargs):
super(NodeGroup, self).__init__(*args, **kwargs)
Expand Down
Loading