From cdc2ad406dd6154cb683e748bf9ff5435ae5a7a5 Mon Sep 17 00:00:00 2001 From: David Dudas Date: Wed, 13 Nov 2024 10:24:56 -0800 Subject: [PATCH] [Issue 2665] Add search path to db connection params (#2836) ## Summary Fixes #2665 ### Time to review: __1 min__ ## Changes proposed > What was added, updated, or removed in this PR. Added search path to db connection params. ## Context for reviewers > Testing instructions, background context, more in-depth details of the implementation, and anything else you'd like to call out or ask reviewers. Explain how the changes were verified. This is latest step in a series of attempts to resolve failed db connections and privileges from /analytics step functions. See ticket history and comments for details. ## Additional information > Screenshots, GIF demos, code examples or output to help show the changes working as expected. --- analytics/config.py | 1 + analytics/local.env | 3 ++- analytics/src/analytics/integrations/db.py | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/analytics/config.py b/analytics/config.py index 9c5cd0bbf..67f620c66 100644 --- a/analytics/config.py +++ b/analytics/config.py @@ -17,6 +17,7 @@ class DBSettings(PydanticBaseEnvConfig): user: str = Field (alias="DB_USER") password: Optional[str] = Field(None, alias="DB_PASSWORD") ssl_mode: str = Field("require", alias="DB_SSL_MODE") + db_schema: str = Field ("app", alias="DB_SCHEMA") slack_bot_token: str = Field(alias="ANALYTICS_SLACK_BOT_TOKEN") reporting_channel_id: str = Field(alias="ANALYTICS_REPORTING_CHANNEL_ID") aws_region: Optional[str] = Field(None, alias="AWS_REGION") diff --git a/analytics/local.env b/analytics/local.env index f8e658c37..eb428ae78 100644 --- a/analytics/local.env +++ b/analytics/local.env @@ -12,6 +12,7 @@ DB_NAME=app DB_USER=app DB_PASSWORD=secret123 DB_SSL_MODE=allow +DB_SCHEMA=public # When an error occurs with a SQL query, # whether or not to hide the parameters which @@ -37,4 +38,4 @@ MB_DB_HOST=grants-analytics-db # Set these in your shell # by doing `export ANALYTICS_REPORTING_CHANNEL_ID=whatever` ANALYTICS_REPORTING_CHANNEL_ID=DO_NOT_SET_HERE -ANALYTICS_SLACK_BOT_TOKEN=DO_NOT_SET_HERE \ No newline at end of file +ANALYTICS_SLACK_BOT_TOKEN=DO_NOT_SET_HERE diff --git a/analytics/src/analytics/integrations/db.py b/analytics/src/analytics/integrations/db.py index 1f907aaa6..cec819829 100644 --- a/analytics/src/analytics/integrations/db.py +++ b/analytics/src/analytics/integrations/db.py @@ -60,6 +60,7 @@ def get_connection_parameters(config: DBSettings) -> dict[str, Any]: "port": config.port, "connect_timeout": 20, "sslmode": config.ssl_mode, + "options": f"-c search_path={config.db_schema}", }