Add Cloud SQL connector DB mode switch with DB schema search_path + CI-safe DB init for auth-provider#46
Conversation
…nector support Co-authored-by: evanpetzoldt <48631145+evanpetzoldt@users.noreply.github.com> Agent-Logs-Url: https://github.com/F3-Nation/f3-nation-auth/sessions/9c96ab8b-9202-488c-b587-e75804d4b908
…ets script Co-authored-by: evanpetzoldt <48631145+evanpetzoldt@users.noreply.github.com> Agent-Logs-Url: https://github.com/F3-Nation/f3-nation-auth/sessions/9c96ab8b-9202-488c-b587-e75804d4b908
…idation Co-authored-by: evanpetzoldt <48631145+evanpetzoldt@users.noreply.github.com> Agent-Logs-Url: https://github.com/F3-Nation/f3-nation-auth/sessions/9c96ab8b-9202-488c-b587-e75804d4b908
evanpetzoldt
left a comment
There was a problem hiding this comment.
This all looks fine to me... I don't suppose @pstaylor-patrick would be able to take a quick look? CC @taterhead247
evanpetzoldt
left a comment
There was a problem hiding this comment.
@copilot see suggestion, we need to use a search path to reach the right destination. This will need to be added to secrets.
Also, the CI build is failing, it says DATABASE_URL is missing; I'm not sure why that is, but I'm guessing it's in load_environment_variables()
…l init for CI Co-authored-by: evanpetzoldt <48631145+evanpetzoldt@users.noreply.github.com> Agent-Logs-Url: https://github.com/F3-Nation/f3-nation-auth/sessions/c31b6414-a65c-49ef-ab8e-531f93287061
Co-authored-by: evanpetzoldt <48631145+evanpetzoldt@users.noreply.github.com> Agent-Logs-Url: https://github.com/F3-Nation/f3-nation-auth/sessions/c31b6414-a65c-49ef-ab8e-531f93287061
Addressed in Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
| function createDirectPool(): Pool { | ||
| const connectionString = process.env.DATABASE_URL; | ||
|
|
||
| if (!connectionString) { | ||
| throw new Error('DATABASE_URL is missing. Cannot connect to the database.'); | ||
| } | ||
|
|
||
| const searchPath = getSearchPath(); | ||
| return new Pool({ connectionString, options: `-c search_path=${searchPath}` }); | ||
| } | ||
|
|
There was a problem hiding this comment.
@copilot DATABASE_URL already has a search path in it... will this break by adding it again in the options argument of the Pool constructor?
There was a problem hiding this comment.
Good catch — I updated this in 8334ae8. In direct mode, if DATABASE_URL already includes search_path/currentSchema (or options with search_path), we now skip adding Pool options so we don’t duplicate/override it. We only add options when the URL does not already set it. UI screenshot: N/A (backend-only change).
… URL mode Co-authored-by: evanpetzoldt <48631145+evanpetzoldt@users.noreply.github.com> Agent-Logs-Url: https://github.com/F3-Nation/f3-nation-auth/sessions/273603c9-4156-45e4-8bc3-bb8611cb4052
evanpetzoldt
left a comment
There was a problem hiding this comment.
Alright, I think this looks good again from my perspective
taterhead247
left a comment
There was a problem hiding this comment.
nothing stands out as terribly bad
👋 TL;DR
Adds an environment-variable DB connection mode switch for auth-provider (direct or Cloud SQL Connector), plus
DB_SCHEMA/search_pathsupport, CI-safe lazy DB initialization, and a direct-mode guard to avoid overriding an existingsearch_pathalready set inDATABASE_URL.🔎 Details
auth-provider/db/index.ts:DB_CONNECTION_MODE=direct(default): usesDATABASE_URLDB_CONNECTION_MODE=connector: uses@google-cloud/cloud-sql-connectorCLOUD_SQL_CONNECTION_NAME,DB_USER,DB_PASSWORD,DB_NAMECLOUD_SQL_IP_TYPE(defaults toPUBLIC)DB_SCHEMA(default:public)options: -c search_path=...options: -c search_path=...only whenDATABASE_URLdoes not already specify schema/search path settingsauth-provider/app/page.tsxnow exportsdynamic = 'force-dynamic'to avoid static page-data collection executing DB queries at build time@google-cloud/cloud-sql-connector@1.9.2auth-provider/.env.exampleauth-provider/README.mdauth-provider/apphosting.yaml(includesDB_SCHEMAand connector-related env/secret entries)auth-provider/scripts/firebase-secrets.sh(mode-aware required vars andDB_SCHEMAsupport)✅ How to Test
npm run installnpm run lintnpm run typecheckDB_CONNECTION_MODE=directDATABASE_URLwith schema/search path (for example, via URL options)DB_CONNECTION_MODE=direct,DATABASE_URL=..., and optionalDB_SCHEMA=public(or comma-separated schemas)DB_SCHEMADB_CONNECTION_MODE=connectorCLOUD_SQL_CONNECTION_NAME,DB_USER,DB_PASSWORD,DB_NAMECLOUD_SQL_IP_TYPE=PUBLIC|PRIVATEDB_SCHEMA(single schema or comma-separated list).env.prodincludesDB_CONNECTION_MODE,DB_SCHEMA, and the appropriate vars for selected modenpm run firebase:secretsDATABASE_URLis unset at build-time data collection🥜 GIF
📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.