Last active
April 23, 2020 17:00
-
-
Save jourdanrodrigues/0e5b9312dff8e1d5f2185d07ae5b1d32 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
from django.conf import settings | |
# The value is the key that goes in the `DATABASES` settings. | |
# Ideally set in the Django settings as well, so it can be project-wide accessible | |
SOURCE_DB_LABEL = 'source_db' | |
class DatabaseRouter: | |
@classmethod | |
def allow_migrate(cls, db_label: str, app_label: str, **hints) -> bool: | |
allow_default = db_label == 'default' and app_label != 'source_service_app' | |
allow_sam_core = db_label == SOURCE_DB_LABEL and app_label in cls._get_django_apps() + ['source_service_app'] | |
return allow_default or allow_sam_core | |
@staticmethod | |
def _get_django_apps(): | |
return [app_label.split('.')[-1] for app_label in settings.DJANGO_APPS] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment