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

Composite foreign key for profiles -> party_member #14

Open
novacrazy opened this issue Aug 3, 2022 · 1 comment
Open

Composite foreign key for profiles -> party_member #14

novacrazy opened this issue Aug 3, 2022 · 1 comment
Labels
enhancement New feature or request help wanted Extra attention is needed SQL

Comments

@novacrazy
Copy link
Member

lantern.party_member already contains a composite primary key of (user_id, party_id), so it would be great to reference that as a composite foreign key in lantern.profiles when user_id and party_id are not-NULL. That way when the party_member entry is deleted, the (if any) per-party profile is also deleted by cascade.

However, profiles.party_id can be NULL for non-party profiles, so I'm currently unsure what exactly that foreign key declaration would look like.

I've found this article as perhaps a starting point.

@novacrazy novacrazy added enhancement New feature or request help wanted Extra attention is needed SQL labels Aug 3, 2022
@novacrazy
Copy link
Member Author

Perhaps as simple as:

ALTER TABLE lantern.profiles ADD CONSTRAINT party_member_fk FOREIGN KEY (user_id, party_id)
    REFERENCES lantern.party_member (user_id, party_id) MATCH PARTIAL
    ON DELETE CASCADE ON UPDATE NO ACTION;

but I'm not sure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed SQL
Projects
None yet
Development

No branches or pull requests

1 participant