mirror of
https://github.com/jazzband/dj-database-url.git
synced 2026-03-16 22:20:24 +00:00
Support schema definition for redshift
In addition to postgres, redshift database is also support schema. Respect it by 'currentSchema' param. Also, we need to not include this param as in in Django's DATABASES settings. Otherwise, following error is raised: ``` django.db.utils.OperationalError: invalid connection option "currentSchema" ```
This commit is contained in:
parent
97bc560445
commit
89a55460d6
2 changed files with 9 additions and 5 deletions
|
|
@ -114,8 +114,11 @@ def parse(url, engine=None, conn_max_age=0):
|
|||
options[key] = values[-1]
|
||||
|
||||
# Support for Postgres Schema URLs
|
||||
if 'currentSchema' in options and engine == 'django.db.backends.postgresql_psycopg2':
|
||||
options['options'] = '-c search_path={0}'.format(options['currentSchema'])
|
||||
if 'currentSchema' in options and engine in (
|
||||
'django.db.backends.postgresql_psycopg2',
|
||||
'django_redshift_backend',
|
||||
):
|
||||
options['options'] = '-c search_path={0}'.format(options.pop('currentSchema'))
|
||||
|
||||
if options:
|
||||
config['OPTIONS'] = options
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ class DatabaseTestSuite(unittest.TestCase):
|
|||
assert url['PASSWORD'] == 'wegauwhgeuioweg'
|
||||
assert url['PORT'] == 5431
|
||||
assert url['OPTIONS']['options'] == '-c search_path=otherschema'
|
||||
|
||||
assert 'currentSchema' not in url['OPTIONS']
|
||||
|
||||
def test_postgres_parsing_with_special_characters(self):
|
||||
url = 'postgres://%23user:%23password@ec2-107-21-253-135.compute-1.amazonaws.com:5431/%23database'
|
||||
|
|
@ -258,7 +258,7 @@ class DatabaseTestSuite(unittest.TestCase):
|
|||
assert url['PORT'] == ''
|
||||
|
||||
def test_redshift_parsing(self):
|
||||
url = 'redshift://uf07k1i6d8ia0v:wegauwhgeuioweg@ec2-107-21-253-135.compute-1.amazonaws.com:5439/d8r82722r2kuvn'
|
||||
url = 'redshift://uf07k1i6d8ia0v:wegauwhgeuioweg@ec2-107-21-253-135.compute-1.amazonaws.com:5439/d8r82722r2kuvn?currentSchema=otherschema'
|
||||
url = dj_database_url.parse(url)
|
||||
|
||||
assert url['ENGINE'] == 'django_redshift_backend'
|
||||
|
|
@ -267,7 +267,8 @@ class DatabaseTestSuite(unittest.TestCase):
|
|||
assert url['USER'] == 'uf07k1i6d8ia0v'
|
||||
assert url['PASSWORD'] == 'wegauwhgeuioweg'
|
||||
assert url['PORT'] == 5439
|
||||
|
||||
assert url['OPTIONS']['options'] == '-c search_path=otherschema'
|
||||
assert 'currentSchema' not in url['OPTIONS']
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
|||
Loading…
Reference in a new issue