mirror of
https://github.com/django-q2/django-q2.git
synced 2026-10-05 08:08:12 +08:00
Feature/improves multiple databases support (#561)
* feat: adds docker local files to ignore * feat: adds replica key to django q settings * feat: adds multiple database routers testing utility * feat: ensures scheduler works with multiple databases and replicas * feat: adds docker image to support containerized development * refactor: removes unnecessary import * style: improves import styling * docs: adds replica setting to configure documentation
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
class TestingReplicaDatabaseRouter:
|
||||
"""
|
||||
A router to control all database operations on models in the
|
||||
auth application.
|
||||
"""
|
||||
|
||||
def db_for_read(self, model, **hints):
|
||||
"""
|
||||
Allows read access from REPLICA database.
|
||||
"""
|
||||
return "replica"
|
||||
|
||||
def db_for_write(self, model, **hints):
|
||||
"""
|
||||
Always write to DEFAULT database
|
||||
"""
|
||||
return "default"
|
||||
|
||||
|
||||
class TestingMultipleAppsDatabaseRouter:
|
||||
"""
|
||||
A router to control all database operations on models in the
|
||||
auth application.
|
||||
"""
|
||||
|
||||
@staticmethod
|
||||
def is_admin(model):
|
||||
return model._meta.app_label in ['admin']
|
||||
|
||||
def db_for_read(self, model, **hints):
|
||||
if self.is_admin(model):
|
||||
return 'admin'
|
||||
return 'default'
|
||||
|
||||
def db_for_write(self, model, **hints):
|
||||
if self.is_admin(model):
|
||||
return 'admin'
|
||||
return 'default'
|
||||
Reference in New Issue
Block a user