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

fix relation and migration methods in db router #78

Merged
merged 2 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/email_relay/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@ def db_for_write(self, model, **hints):
return "default"

def allow_relation(self, obj1, obj2, **hints):
return True
if (
obj1._meta.app_label == "email_relay"
or obj2._meta.app_label == "email_relay"
):
return True
return None

def allow_migrate(self, db, app_label, model_name=None, **hints):
return True
if app_label == "email_relay":
return db == app_settings.DATABASE_ALIAS
return None
4 changes: 2 additions & 2 deletions tests/test_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ def test_db_for_write(router):


def test_allow_relation(router):
assert router.allow_relation(None, None)
assert router.allow_relation(MockModel, MockModel)


def test_allow_migrate(router):
assert router.allow_migrate("some_db", "some_app_label")
assert router.allow_migrate(app_settings.DATABASE_ALIAS, "email_relay")