-
Notifications
You must be signed in to change notification settings - Fork 4
jir-ogc #554
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
jir-ogc #554
Changes from all commits
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 | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -38,6 +38,19 @@ | |||||||||||||||||||||||
| # environment variables already set by the runtime (e.g., Cloud Run jobs). | ||||||||||||||||||||||||
| load_dotenv(override=False) | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| # In managed runtime environments, DB_DRIVER is occasionally omitted while | ||||||||||||||||||||||||
| # CLOUD_SQL_* vars are present. Default to cloudsql in that case to avoid | ||||||||||||||||||||||||
| # silently falling back to localhost/postgres settings. | ||||||||||||||||||||||||
| if ( | ||||||||||||||||||||||||
| not (os.getenv("DB_DRIVER") or "").strip() | ||||||||||||||||||||||||
| and (os.getenv("CLOUD_SQL_INSTANCE_NAME") or "").strip() | ||||||||||||||||||||||||
| ): | ||||||||||||||||||||||||
| os.environ["DB_DRIVER"] = "cloudsql" | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| # Cloud SQL should use IAM auth by default unless explicitly disabled. | ||||||||||||||||||||||||
| if (os.getenv("DB_DRIVER") or "").strip().lower() == "cloudsql": | ||||||||||||||||||||||||
| os.environ.setdefault("CLOUD_SQL_IAM_AUTH", "true") | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| from alembic import command | ||||||||||||||||||||||||
| from alembic.config import Config | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
|
|
@@ -690,20 +703,30 @@ def _transfer_parallel( | |||||||||||||||||||||||
| def main(): | ||||||||||||||||||||||||
| message("START--------------------------------------") | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| # Display database configuration for verification | ||||||||||||||||||||||||
| db_name = os.getenv("POSTGRES_DB", "postgres") | ||||||||||||||||||||||||
| db_host = os.getenv("POSTGRES_HOST", "localhost") | ||||||||||||||||||||||||
| db_port = os.getenv("POSTGRES_PORT", "5432") | ||||||||||||||||||||||||
| message(f"Database Configuration: {db_host}:{db_port}/{db_name}") | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| # Double-check we're using the development database | ||||||||||||||||||||||||
| if db_name != "ocotilloapi_dev": | ||||||||||||||||||||||||
| message(f"WARNING: Using database '{db_name}' instead of 'ocotilloapi_dev'") | ||||||||||||||||||||||||
| if db_name in ("ocotilloapi_test", "nmsamplelocations_test"): | ||||||||||||||||||||||||
| raise ValueError( | ||||||||||||||||||||||||
| "ERROR: Cannot run transfer on test database! " | ||||||||||||||||||||||||
| "Set POSTGRES_DB=ocotilloapi_dev in .env file" | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
| db_driver = (os.getenv("DB_DRIVER") or "").strip().lower() | ||||||||||||||||||||||||
| if db_driver == "cloudsql": | ||||||||||||||||||||||||
| db_name = os.getenv("CLOUD_SQL_DATABASE", "") | ||||||||||||||||||||||||
| instance_name = os.getenv("CLOUD_SQL_INSTANCE_NAME", "") | ||||||||||||||||||||||||
| iam_auth = os.getenv("CLOUD_SQL_IAM_AUTH", "") | ||||||||||||||||||||||||
|
Comment on lines
+707
to
+710
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.
When Useful? React with 👍 / 👎. |
||||||||||||||||||||||||
| message( | ||||||||||||||||||||||||
| "Database Configuration: " | ||||||||||||||||||||||||
| f"driver=cloudsql instance={instance_name} db={db_name} iam_auth={iam_auth}" | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
| ) | |
| ) | |
| # Double-check we're using the development database for Cloud SQL as well | |
| if db_name != "ocotilloapi_dev": | |
| message(f"WARNING: Using database '{db_name}' instead of 'ocotilloapi_dev'") | |
| if db_name in ("ocotilloapi_test", "nmsamplelocations_test"): | |
| raise ValueError( | |
| "ERROR: Cannot run transfer on test database! " | |
| "Set CLOUD_SQL_DATABASE=ocotilloapi_dev in environment" | |
| ) |
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.
Comment/condition mismatch: the comment says "CLOUD_SQL_* vars are present", but the fallback to cloudsql only checks
CLOUD_SQL_INSTANCE_NAME. Either update the comment to match the actual condition, or expand the condition to check the required Cloud SQL vars you expect to be present (e.g., database/user) before forcing DB_DRIVER=cloudsql.