-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pass schema in credentials to Postgresql #1476
Changes from 6 commits
355d2ad
a2ffe8e
f1eaeb4
63ef8e3
2f5aa3b
82f1656
2f4e92a
0f5ce12
4e7c096
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,3 +76,6 @@ target/ | |
|
||
# Vim | ||
*.sw* | ||
|
||
# PyCharm | ||
.idea/* |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,9 @@ | |
'schema': { | ||
'type': 'string', | ||
}, | ||
'search_path': { | ||
'type': 'string', | ||
}, | ||
'keepalives_idle': { | ||
'type': 'integer', | ||
}, | ||
|
@@ -53,7 +56,7 @@ def type(self): | |
return 'postgres' | ||
|
||
def _connection_keys(self): | ||
return ('host', 'port', 'user', 'database', 'schema') | ||
return ('host', 'port', 'user', 'database', 'schema', 'search_path') | ||
|
||
|
||
class PostgresConnectionManager(SQLConnectionManager): | ||
|
@@ -105,6 +108,12 @@ def open(cls, connection): | |
if keepalives_idle: | ||
kwargs['keepalives_idle'] = keepalives_idle | ||
|
||
# psycopg2 doesn't support search_path officially, see https:/psycopg/psycopg2/issues/465 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
search_path = credentials.get('search_path') | ||
if search_path is not None and search_path != '': | ||
# see https://www.postgresql.org/docs/9.5/libpq-connect.html#LIBPQ-CONNECT-OPTIONS | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
kwargs['options'] = '-c search_path={}'.format(search_path.replace(' ', '\\ ')) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
try: | ||
handle = psycopg2.connect( | ||
dbname=credentials.database, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,6 +55,9 @@ | |
'If using IAM auth, the ttl for the temporary credentials' | ||
) | ||
}, | ||
'search_path': { | ||
'type': 'string', | ||
}, | ||
'keepalives_idle': { | ||
'type': 'integer', | ||
}, | ||
|
@@ -75,7 +78,7 @@ def type(self): | |
return 'redshift' | ||
|
||
def _connection_keys(self): | ||
return ('host', 'port', 'user', 'database', 'schema', 'method') | ||
return ('host', 'port', 'user', 'database', 'schema', 'method', 'search_path') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
|
||
class RedshiftConnectionManager(PostgresConnectionManager): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you remove this? you can create a
.gitignore
locally without including it in this repo's.gitignore
. Instructions here: https://help.github.com/en/articles/ignoring-files#create-a-global-gitignore