Skip to content

feat(api): POSTGRES_DB_PREFIX for database-name resolution#4684

Open
jp-agenta wants to merge 1 commit into
mainfrom
feat/postgres-db-prefix
Open

feat(api): POSTGRES_DB_PREFIX for database-name resolution#4684
jp-agenta wants to merge 1 commit into
mainfrom
feat/postgres-db-prefix

Conversation

@jp-agenta

Copy link
Copy Markdown
Member

Context

Switching a deployment between editions today means retyping full POSTGRES_URI_* values, credentials included, because the default database names embed the license (agenta_oss_core vs agenta_ee_core).

Changes

One knob: explicit POSTGRES_URI_* wins; else URIs compose from POSTGRES_DB_PREFIX plus the existing POSTGRES_USER/PASSWORD/PORT vars; else today's default agenta_{license}. An EE stack adopting an OSS database sets POSTGRES_DB_PREFIX=agenta_oss and nothing else.

What to QA

Unset prefix: URIs identical to before. Set POSTGRES_DB_PREFIX=agenta_oss on an EE stack: all three URIs point at the agenta_oss_* databases.

🤖 Generated with Claude Code

@dosubot dosubot Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Jun 12, 2026
@vercel

vercel Bot commented Jun 12, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
agenta-documentation Ready Ready Preview, Comment Jun 14, 2026 6:03pm

Request Review

@dosubot dosubot Bot added the Backend label Jun 12, 2026
@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: b6ea4569-89ee-400f-961e-38ad7a680c7c

📥 Commits

Reviewing files that changed from the base of the PR and between 766d9d7 and ae72462.

📒 Files selected for processing (1)
  • api/oss/src/utils/env.py

📝 Walkthrough

Summary by CodeRabbit

  • Chores
    • Improved database configuration flexibility by introducing a customizable database name prefix via environment variables.
    • Updated default database connection strings to be safely composed using URL-encoded credentials, preventing special characters from breaking connections.
    • Continued support for explicit connection string overrides via existing environment variables.

Walkthrough

PostgresConfig in env.py gains a db_prefix field sourced from POSTGRES_DB_PREFIX (defaulting to agenta_{_LICENSE}). Credentials are URL-encoded via quote_plus for safe DSN composition. Default values for uri_core, uri_tracing, and uri_supertokens are updated to interpolate user, password, port, and db_prefix instead of using hardcoded credentials and database names.

Changes

PostgreSQL Database Prefix and URI Refactoring

Layer / File(s) Summary
PostgreSQL database prefix, credential encoding, and URI defaults
api/oss/src/utils/env.py
Import quote_plus for credential encoding. Add db_prefix field resolved from POSTGRES_DB_PREFIX (defaulting to agenta_{_LICENSE}), explicitly source user, password, and port from environment. URL-encode credentials into _user_q and _password_q for safe DSN composition. Refactor defaults for uri_core, uri_tracing, and uri_supertokens to interpolate encoded credentials, port, and database names derived from `{db_prefix}_{core

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 60.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: introducing POSTGRES_DB_PREFIX for controlling database name resolution in PostgreSQL configuration.
Description check ✅ Passed The description clearly explains the context, changes, and QA testing approach, directly related to the implementation of POSTGRES_DB_PREFIX for flexible database naming.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/postgres-db-prefix

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: b9d888b3-2a77-4e46-b2d9-efde6224b298

📥 Commits

Reviewing files that changed from the base of the PR and between a2e9150 and 836837f.

📒 Files selected for processing (1)
  • api/oss/src/utils/env.py

Comment thread api/oss/src/utils/env.py Outdated
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Jun 14, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
api/entrypoints/worker_events.py (1)

26-27: ⚡ Quick win

Consolidate the duplicated MAXLEN_QUEUES_WEBHOOKS constant. Both files configure the same Redis stream queues:webhooks and define the same constant with identical values. Extract to a shared location to maintain a single source of truth.

  • api/entrypoints/worker_events.py#L26-L27: Move this constant to a shared constants module (e.g., api/oss/src/tasks/taskiq/webhooks/constants.py) or import from the other worker.
  • api/entrypoints/worker_webhooks.py#L29-L30: Import the constant instead of redefining it.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: a7ca027d-fafc-42b7-988e-4d5d4120457f

📥 Commits

Reviewing files that changed from the base of the PR and between 836837f and bad3bc9.

⛔ Files ignored due to path filters (4)
  • api/uv.lock is excluded by !**/*.lock
  • clients/python/uv.lock is excluded by !**/*.lock
  • sdks/python/uv.lock is excluded by !**/*.lock
  • services/uv.lock is excluded by !**/*.lock
📒 Files selected for processing (20)
  • api/entrypoints/worker_evaluations.py
  • api/entrypoints/worker_events.py
  • api/entrypoints/worker_webhooks.py
  • api/oss/src/core/events/streaming.py
  • api/oss/src/core/tracing/streaming.py
  • api/oss/src/utils/env.py
  • api/oss/tests/legacy/conftest.py
  • api/oss/tests/legacy/workflows/core/tests.py
  • api/pyproject.toml
  • clients/python/pyproject.toml
  • docs/openapi-cleanup/research.md
  • hosting/kubernetes/helm/Chart.yaml
  • sdks/python/oss/tests/legacy/new_tests/conftest.py
  • sdks/python/oss/tests/legacy/new_tests/workflows/core/tests.py
  • sdks/python/pyproject.toml
  • services/pyproject.toml
  • web/ee/package.json
  • web/oss/package.json
  • web/package.json
  • web/packages/agenta-api-client/package.json
✅ Files skipped from review due to trivial changes (10)
  • web/package.json
  • web/packages/agenta-api-client/package.json
  • services/pyproject.toml
  • clients/python/pyproject.toml
  • sdks/python/pyproject.toml
  • api/pyproject.toml
  • hosting/kubernetes/helm/Chart.yaml
  • web/oss/package.json
  • web/ee/package.json
  • docs/openapi-cleanup/research.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • api/oss/src/utils/env.py

Comment thread api/oss/tests/legacy/conftest.py
@junaway junaway force-pushed the feat/postgres-db-prefix branch from bad3bc9 to 766d9d7 Compare June 14, 2026 17:39
@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Jun 14, 2026
Explicit POSTGRES_URI_* wins; else URIs compose from POSTGRES_DB_PREFIX plus
the existing user/password/port vars; else today's default agenta_{license}.
One knob for edition switches (EE stack pointing at agenta_oss_* databases)
without retyping credentials.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Backend size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant