Last active
December 5, 2019 09:58
-
-
Save AndreasDickow/f277191dd948b5f76260af027f843acf to your computer and use it in GitHub Desktop.
Set default schema for Postgresql DB in django
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
# with this trick it is possible to install django on schema access restricted databases | |
# within project root create folders like | |
# -app | |
# -pg | |
# | | |
# - __init__.py | |
# - base.py | |
from django.db.backends.postgresql_psycopg2.base import DatabaseWrapper | |
class DatabaseWrapper(DatabaseWrapper): | |
def __init__(self, *args, **kwargs): | |
super(DatabaseWrapper, self).__init__(*args, **kwargs) | |
def _cursor(self, *args, **kwargs): | |
cursor = super(DatabaseWrapper, self)._cursor(*args, **kwargs) | |
if not kwargs: | |
cursor.execute('SET search_path = <your-db-schema>') | |
return cursor |
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
DATABASES = { | |
'default': { | |
'ENGINE': 'app.pg', | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment