Skip to content

fix: use Docker service name 'postgres' as default DB host in alembic.ini - #1705

Open
esazonova wants to merge 1 commit into
genlayerlabs:v0.123-devfrom
esazonova:fix/1698-alembic-default-host
Open

fix: use Docker service name 'postgres' as default DB host in alembic.ini#1705
esazonova wants to merge 1 commit into
genlayerlabs:v0.123-devfrom
esazonova:fix/1698-alembic-default-host

Conversation

@esazonova

@esazonova esazonova commented Jul 15, 2026

Copy link
Copy Markdown

Summary

This PR fixes the database migration container failing on fresh genlayer up by updating the default sqlalchemy.url in alembic.ini to use the Docker service name postgres instead of localhost.

Problem

The database-migration container was failing with:

connection to server at "localhost" (::1), port 5432 failed: Connection refused

This happened because alembic.ini hardcoded localhost as the database host, but in Docker Compose the PostgreSQL service is accessible via the service name postgres, not localhost.

Solution

Changed the default sqlalchemy.url in alembic.ini from:

postgresql://postgres:postgres@localhost/genlayer_state

to:

postgresql://postgres:postgres@postgres:5432/genlayer_state

This matches the Docker Compose service name and the default DBHOST value in .env.example.

Testing

  • Verified that env.py still properly overrides this URL with environment variables
  • The change only affects the default fallback value when DBHOST is not set

Fixes #1698

Summary by CodeRabbit

  • Chores
    • Updated database configuration to support PostgreSQL connections through the Docker service.
    • Clarified that runtime environment settings can override connection details.

….ini

Change the default sqlalchemy.url in alembic.ini from localhost to
postgres (the Docker service name). This ensures the database-migration
container can connect to PostgreSQL when running in Docker Compose,
even if the DBHOST environment variable is not explicitly set.

Fixes genlayerlabs#1698
@github-actions
github-actions Bot changed the base branch from main to v0.123-dev July 15, 2026 20:30
@github-actions

Copy link
Copy Markdown
Contributor

This PR targeted main, which is only the default/static branch.

I retargeted it to v0.123-dev, the active development branch. Pushes to v0.123-dev automatically fast-forward main.

@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Alembic’s default PostgreSQL URL now targets the Docker postgres service on port 5432. Comments clarify that env.py can override connection details using runtime environment variables.

Changes

Database migration configuration

Layer / File(s) Summary
Update Alembic connection settings
backend/database_handler/alembic.ini
The default SQLAlchemy URL changes from localhost to postgres:5432, and comments document runtime environment-variable overrides.

Estimated code review effort: 1 (Trivial) | ~2 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: switching the default Alembic DB host to the Docker service name.
Description check ✅ Passed The description covers the summary, problem, solution, testing, and issue reference, with only non-critical template sections omitted.
Linked Issues check ✅ Passed The change matches #1698 by replacing the hardcoded localhost default with the Docker service alias postgres.
Out of Scope Changes check ✅ Passed The PR appears scoped to the Alembic URL default update and does not introduce unrelated code changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@backend/database_handler/alembic.ini`:
- Around line 63-65: Update the URL selection in env.py so the runtime
DB_URL/DBHOST configuration is used when provided, but the Alembic
sqlalchemy.url value is preserved when runtime configuration is absent; ensure
fresh Compose startup resolves the postgres service host instead of defaulting
to localhost.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9927bd4b-4b33-489c-8ecb-d150c04d9af7

📥 Commits

Reviewing files that changed from the base of the PR and between 4fde150 and f4c8011.

📒 Files selected for processing (1)
  • backend/database_handler/alembic.ini

Comment on lines +63 to +65
# Default URL uses Docker service name 'postgres' as host.
# Overridden at runtime by env.py using DBHOST, DBUSER, DBPASSWORD, DBPORT, DBNAME env vars.
sqlalchemy.url = postgresql://postgres:postgres@postgres:5432/genlayer_state

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

The new default URL is bypassed by env.py.

backend/database_handler/migration/env.py always assigns url from DB_URL; when DBHOST is unset, that code defaults to localhost instead of falling back to this Alembic setting. Therefore, changing this line to postgres does not fix the fresh genlayer up path. Update env.py to use the INI URL when runtime configuration is absent, or ensure Compose supplies DBHOST=postgres by default.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@backend/database_handler/alembic.ini` around lines 63 - 65, Update the URL
selection in env.py so the runtime DB_URL/DBHOST configuration is used when
provided, but the Alembic sqlalchemy.url value is preserved when runtime
configuration is absent; ensure fresh Compose startup resolves the postgres
service host instead of defaulting to localhost.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

simulator-database-migration:latest — alembic.ini appears to hardcode localhost, migration container exits 1 on fresh genlayer up

2 participants