-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add multi-tenancy support for Postgres (#383)
This PR addresses 382 and adds naive support for multi-tenancy with a "MULTITENANCY" flag. Domain context can now be initialized witn arbitrary attributes. In our case, we will be setting MULTITENANCY to True. Improvements to be done: - a better way to supply database info in a multi-tenancy use case - reset database connection to default after execution
- Loading branch information
Showing
5 changed files
with
55 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
26 changes: 26 additions & 0 deletions
26
tests/adapters/repository/sqlalchemy_repo/postgresql/test_schema_switch.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import pytest | ||
|
||
from protean.globals import current_domain | ||
|
||
from .elements import Person | ||
|
||
|
||
# @pytest.mark.postgresql | ||
class TestSchemaSwitch: | ||
@pytest.fixture(autouse=True) | ||
def register_elements(self, test_domain): | ||
test_domain.register(Person) | ||
|
||
def test_schema_switch(self, test_domain): | ||
repo = test_domain.repository_for(Person) | ||
assert repo._provider._metadata.schema == "public" | ||
|
||
with current_domain.domain_context(MULTITENANCY=True): | ||
current_domain.config["DATABASES"]["default"]["SCHEMA"] = "private" | ||
|
||
repo1 = current_domain.repository_for(Person) | ||
assert repo1._provider._metadata.schema == "private" | ||
|
||
# FIXME Reset the database info to default outside the context | ||
# repo2 = test_domain.repository_for(Person) | ||
# assert repo2._provider._metadata.schema == "public" |
This file contains 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