Merge pull request #78 from st4lk/fix-redshift-support

Support schema definition for redshift
This commit is contained in:
Kenneth Reitz 2016-11-28 19:26:44 -05:00 committed by GitHub
commit f1b7985be1
2 changed files with 9 additions and 5 deletions

View file

@ -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

View file

@ -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__':