Skip to content

Commit 9464c36

Browse files
authored
Fix database routers (#125)
* temp disable db routers * uncomment databse router
1 parent 2f93c2e commit 9464c36

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

sensorsafrica/router.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from django.conf import settings
44

55
class ReplicaRouter:
6-
read_replicas = settings.READ_DATABASE_URLS
6+
read_replicas = list(settings.DATABASES.keys())
77

88
def db_for_read(self, model, **hints):
99
return random.choice(self.read_replicas)

sensorsafrica/settings.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,12 @@
113113

114114
DATABASES = {"default": dj_database_url.parse(DATABASE_URL), }
115115

116-
# READ_DATABASE_URLS = os.getenv("SENSORSAFRICA_READ_DATABASE_URLS", DATABASE_URL).split(",")
116+
READ_DATABASE_URLS = os.getenv("SENSORSAFRICA_READ_DATABASE_URLS", DATABASE_URL).split(",")
117117

118-
# for index, read_database_url in enumerate(READ_DATABASE_URLS,start=1):
119-
# DATABASES[f"read_replica_{index}"] = dj_database_url.parse(read_database_url)
118+
for index, read_database_url in enumerate(READ_DATABASE_URLS,start=1):
119+
DATABASES[f"read_replica_{index}"] = dj_database_url.parse(read_database_url)
120120

121-
# DATABASE_ROUTERS = ["sensorsafrica.router.ReplicaRouter", ]
121+
DATABASE_ROUTERS = ["sensorsafrica.router.ReplicaRouter", ]
122122

123123
# Password validation
124124
# https://docs.djangoproject.com/en/1.10/ref/settings/#auth-password-validators

0 commit comments

Comments
 (0)