citusdata / django-multitenant

Python/Django support for distributed multi-tenant databases like Postgres+Citus
MIT License
721 stars 119 forks source link

Multiple Django ORM compatibility improvements #16

Closed gsgalloway closed 6 years ago

gsgalloway commented 6 years ago

This PR based off PR #14.

Addresses issues #15 and #11

Changes:

  1. Split apart library into multiple files. Importing the utility function get_current_tenant would cause errors due to the import statement triggering evaluation of the TenantModel class. This would cause problems if TenantModel were evaluated before the database backend was initialized.
  2. Added a simple TenantOneToOneField which does not try to enforce a uniqueness constraint on the ID column, but preserves all the relationship semantics of using a traditional OneToOneField in Django.
  3. Overrode Django's DatabaseSchemaEditor to produce foreign key constraints on composite foreign keys consisting of both the ID and tenant ID columns for any foreign key between TenantModels
  4. Monkey-patched Django's DeleteQuery implementation to include tenant_id in its SQL queries.
saicitus commented 6 years ago

Hey @gsgalloway thanks a lot for this great PR. It takes the library to a whole new level. Appreciate your contributions. Sorry for not getting to this earlier. I reviewed, merged and even created a new release! Cheers.