'Django with Postgres - Unique Constraint for One Tenant in Multitenant Database

I've been reading and reading and reading, but finally decided to shortlist my questions regarding multitenant Postgres with Django. I'm quite new with using Django, so please bear with me.

We are developing a multitenant business platform with more than 300 tables. For tenants' ids, we have chosen UUID4, so there are my questions coming:

  1. Is it enough to use UUID4 for tenants' and users' ids only and then reference them as foreign keys in every other table? If not,
  2. Is there a need to use UUID4 in every table? That means that pk in each table will be UUID and that table will have all foreign keys as UUID4s as well.... The second solution would be the UUID4 for tenants' and users' pks only. Other tables would have bigint pks and only 2 foreign keys as UUID (tenant & user).
  3. In some tables, we need to have other unique data than just pk (such as names, document numbers, tax data and so on). Is there a way to determine/check the uniqueness of such data in a tenant dataset by db constraint or should that be solved by code?
  4. The data volume and number of tenants and users are in millions of rows per year, just to mention.

I would appreciate all your thoughts, links or any other source for further study.

Thanks!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source