Skip to content

Commit

Permalink
Merge pull request #158 from ratson/postgres-socket
Browse files Browse the repository at this point in the history
Support PostgreSQL unix domain socket paths
  • Loading branch information
joke2k committed Jun 25, 2018
2 parents b64b6aa + 7e22a9b commit 6afb6b4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions environ/environ.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,9 @@ def db_url_config(cls, url, engine=None):
'PORT': _cast_int(url.port) or '',
})

if url.scheme == 'postgres' and path.startswith('/'):
config['HOST'], config['NAME'] = path.rsplit('/', 1)

if url.scheme == 'oracle' and path == '':
config['NAME'] = config['HOST']
config['HOST'] = ''
Expand Down
10 changes: 9 additions & 1 deletion environ/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,14 @@ def test_postgres_parsing(self):
self.assertEqual(url['PASSWORD'], 'wegauwhgeuioweg')
self.assertEqual(url['PORT'], 5431)

def test_postgres_parsing_unix_domain_socket(self):
url = 'postgres:////var/run/postgresql/db'
url = Env.db_url_config(url)

self.assertEqual(url['ENGINE'], 'django.db.backends.postgresql_psycopg2')
self.assertEqual(url['NAME'], 'db')
self.assertEqual(url['HOST'], '/var/run/postgresql')

def test_postgis_parsing(self):
url = 'postgis://uf07k1i6d8ia0v:wegauwhgeuioweg@ec2-107-21-253-135.compute-1.amazonaws.com:5431/d8r82722r2kuvn'
url = Env.db_url_config(url)
Expand Down Expand Up @@ -554,7 +562,7 @@ def test_redis_socket_url(self):
self.assertEqual(url['OPTIONS'], {
'DB': 0
})

def test_options_parsing(self):
url = 'filecache:///var/tmp/django_cache?timeout=60&max_entries=1000&cull_frequency=0'
url = Env.cache_url_config(url)
Expand Down

0 comments on commit 6afb6b4

Please sign in to comment.