django-utils

personal collection of django utilities
git clone https://git.ce9e.org/django-utils.git

commit
6ac318305cd2080b3f6038ce38b75030a02503b3
parent
aff583d84e6d5e36ee358c044ec89e5b53eec044
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2019-09-15 08:45
rm db_routers

Diffstat

D utils/db_routers.py 49 -------------------------------------------------

1 files changed, 0 insertions, 49 deletions


diff --git a/utils/db_routers.py b/utils/db_routers.py

@@ -1,49 +0,0 @@
    1    -1 from django.apps import apps
    2    -1 from django.conf import settings
    3    -1 
    4    -1 
    5    -1 class AppDBRouter:
    6    -1     """Route specific apps to specific databases.
    7    -1 
    8    -1     This router makes no statements about other apps, i.e. there is no
    9    -1     guarantee that an app has exclusive access to a database. While
   10    -1     database access is routed to 'default' by default, migrations are
   11    -1     executed on all databases.
   12    -1 
   13    -1     Example configuration::
   14    -1 
   15    -1         APP_DB_ROUTER = {
   16    -1             'some.app': 'database1',
   17    -1             'other.app': 'database2',
   18    -1         }
   19    -1     """
   20    -1 
   21    -1     def db_for_read(self, model, **hints):
   22    -1         app_label = model._meta.app_label
   23    -1         return settings.APP_DB_ROUTER.get(app_label)
   24    -1 
   25    -1     def db_for_write(self, model, **hints):
   26    -1         return self.db_for_read(model, **hints)
   27    -1 
   28    -1     def allow_migrate(self, db, app_label, model_name=None, **hints):
   29    -1         _db = settings.APP_DB_ROUTER.get(app_label)
   30    -1         if _db is not None:
   31    -1             return db == _db
   32    -1 
   33    -1 
   34    -1 class ModelDBRouter:
   35    -1     def db_for_read(self, model, **hints):
   36    -1         model_label = model._meta.label
   37    -1         return settings.MODEL_DB_ROUTER.get(model_label)
   38    -1 
   39    -1     def db_for_write(self, model, **hints):
   40    -1         return self.db_for_read(model, **hints)
   41    -1 
   42    -1     def allow_migrate(self, db, app_label, model_name=None, **hints):
   43    -1         if model_name:
   44    -1             model = apps.get_model(app_label, model_name)
   45    -1             _db = self.db_for_write(model)
   46    -1             if _db:
   47    -1                 return db == _db
   48    -1             elif db in settings.MODEL_DB_ROUTER.values():
   49    -1                 return False