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

Create unique constraints at the db_dbgroup_dbnodes table in SQLA #1678

Closed
szoupanos opened this issue Jun 22, 2018 · 1 comment
Closed

Create unique constraints at the db_dbgroup_dbnodes table in SQLA #1678

szoupanos opened this issue Jun 22, 2018 · 1 comment
Assignees
Milestone

Comments

@szoupanos
Copy link
Contributor

There is a ManyToMany relationship between AiiDA groups and nodes.
This is translated at database level with an intermediate table correlating nodes (dbnodes) and groups (dbgroups).

aiidadb_sqla1=# \d db_dbgroup_dbnodes
                           Table "public.db_dbgroup_dbnodes"
   Column   |  Type   |                            Modifiers
------------+---------+-----------------------------------------------------------------
 id         | integer | not null default nextval('db_dbgroup_dbnodes_id_seq'::regclass)
 dbnode_id  | integer |
 dbgroup_id | integer |
Indexes:
    "db_dbgroup_dbnodes_pkey" PRIMARY KEY, btree (id)
Foreign-key constraints:
    "db_dbgroup_dbnodes_dbgroup_id_fkey" FOREIGN KEY (dbgroup_id) REFERENCES db_dbgroup(id) DEFERRABLE INITIALLY DEFERRED
    "db_dbgroup_dbnodes_dbnode_id_fkey" FOREIGN KEY (dbnode_id) REFERENCES db_dbnode(id) DEFERRABLE INITIALLY DEFERRED

In this table, it is normal to have only one occurrence of group-node.
Therefore a uniqueness constraint should be added.

Moreover, for uniformity reasons, an index should be added on the group and on the node column to match the Django schema and increase the speed of any kind of containment checks.

E.g.

aiidadb_sqla_issue_1319=# \d db_dbgroup_dbnodes
                           Table "public.db_dbgroup_dbnodes"
   Column   |  Type   |                            Modifiers
------------+---------+-----------------------------------------------------------------
 id         | integer | not null default nextval('db_dbgroup_dbnodes_id_seq'::regclass)
 dbnode_id  | integer |
 dbgroup_id | integer |
Indexes:
    "db_dbgroup_dbnodes_pkey" PRIMARY KEY, btree (id)
    "db_dbgroup_dbnodes_dbgroup_id_dbnode_id_key" UNIQUE, btree (dbgroup_id, dbnode_id)
    "db_dbgroup_dbnodes_7a672316" btree (dbnode_id)
    "db_dbgroup_dbnodes_a0b4eda0" btree (dbgroup_id)
Foreign-key constraints:
    "db_dbgroup_dbnodes_dbgroup_id_fkey" FOREIGN KEY (dbgroup_id) REFERENCES db_dbgroup(id) DEFERRABLE INITIALLY DEFERRED
    "db_dbgroup_dbnodes_dbnode_id_fkey" FOREIGN KEY (dbnode_id) REFERENCES db_dbnode(id) DEFERRABLE INITIALLY DEFERRED

This is related to the comment of Martin at #1319
#1319 (comment)
and to the pull request #1677

@szoupanos szoupanos added this to the v0.12.2 milestone Jun 22, 2018
@szoupanos szoupanos self-assigned this Jun 22, 2018
@szoupanos szoupanos changed the title Create unique constrain at the db_dbgroup_dbnodes table in SQLA Create unique constraints at the db_dbgroup_dbnodes table in SQLA Jun 22, 2018
@sphuber
Copy link
Contributor

sphuber commented Jun 25, 2018

Fixed in PR #1680

@sphuber sphuber closed this as completed Jun 25, 2018
@sphuber sphuber modified the milestones: v0.12.2, v1.0.0 Jul 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants