Last active
December 14, 2015 22:19
-
-
Save rintaun/5157422 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| +---------------+ | |
| | organizations | | |
| +---------------+ | |
| +------>| id(PK) |<---------+ | |
| | +---------------+ | | |
| | | | |
| | +--------+ +----------+ | | |
| | | groups | | profiles | | | |
| | +--------+ +----------+ | | |
| +---| org_id | | org_id |---+ | |
| +-->| id(PK) | | id(PK) |<--+ | |
| | +--------+ +----------+ | | |
| | | | |
| | +----------------+ | | |
| | | group_profiles | | | |
| | +----------------+ | | |
| +-------| group_id | | | |
| | profile_id |---------+ | |
| +----------------+ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In the file
without_org_id_fk, entries ingroup_profilescannot guarantee that the referencedgroupandprofilewill be owned by the sameorganization.In order to guarantee this,
group_profilesmust have anorg_idattribute as well, and reference it in its relationships with bothgroupsandprofiles.Currently, this requires an additional constraint --
UNIQUE (id, org_id)-- on bothgroupsandprofiles; without it PG complains:However, a set of attributes is necessarily unique if one or more of the attributes contained in that set is unique. Which is to say, the uniqueness of the keys is implied as the
idattribute in each case is a PK.