Skip to content

chore(enterprise): enforce PostgreSQL-only migrations - #95

Merged
simonrosenberg merged 2 commits into
mainfrom
cleanup-postgresql-only-migrations
Aug 3, 2026
Merged

simonrosenberg merged 2 commits into
mainfrom
cleanup-postgresql-only-migrations

Conversation

@simonrosenberg

@simonrosenberg simonrosenberg commented Jul 29, 2026 •

Copy link
Copy Markdown
Member

HUMAN:

Follow-up cleanup requested after PR #12 exposed that historical migration test scaffolding could be mistaken for supported SQLite migrations.

  • A human has tested these changes.

AGENT:

Removed unsupported migration dialect paths, added a static regression check, and validated the complete migration chain against PostgreSQL 16.


Why

The enterprise Alembic environment has always created PostgreSQL connections and acquires a PostgreSQL advisory lock. It cannot run enterprise migrations on SQLite.

Revision 115 nevertheless contained a SQLite branch solely so a unit test could execute the migration against an in-memory SQLite database. Revision 114 similarly skipped its PostgreSQL backfill on other dialects. These paths were unreachable through the supported migration runner, but they misleadingly suggested cross-database support and encouraged the same pattern to be copied into PR #12.

Summary

  • Make revision 114 execute its PostgreSQL backfill unconditionally.
  • Make revision 115 create only the PostgreSQL partial unique index.
  • Replace the SQLite-backed migration fixture with PostgreSQL statement and operation assertions.
  • Reject SQLite references in enterprise migration files during the static integrity check.
  • Clarify that SQLite remains appropriate for application unit tests, not Alembic migrations.

Issue Number

Follow-up to #12; no separate issue.

How to Test

poetry run python scripts/check_enterprise_migration_integrity.py
poetry run pytest -q tests/unit/test_enterprise_migration_integrity.py

Results: integrity check passed; 10 passed.

PYTHONPATH=".:${PYTHONPATH}" poetry run --project=enterprise pytest -q \
  -p no:ddtrace -p no:ddtrace.pytest_bdd -p no:ddtrace.pytest_benchmark \
  enterprise/tests/unit/storage/test_jira_dc_active_link_constraint.py

Result: 7 passed.

PYTHONPATH=".:${PYTHONPATH}" poetry run --project=enterprise pytest -q \
  -p no:ddtrace -p no:ddtrace.pytest_bdd -p no:ddtrace.pytest_benchmark \
  enterprise/tests/unit/test_migration_*.py \
  tests/unit/test_enterprise_migration_integrity.py

Result: 25 passed.

Both the root and enterprise Python pre-commit configurations passed on every touched Python file, including Ruff, formatting, and mypy.

The full migration chain was also applied from an empty PostgreSQL 16 database with both pg8000 and psycopg2. In a separate seeded run, revision 115 reduced two active links for one user to the newest row, created the partial unique index, rejected another active link, and then upgraded successfully through revision 141.

Video/Screenshots

Not applicable; this is migration and test infrastructure cleanup.

Type

  • Bug fix
  • Feature
  • Refactor
  • Breaking change
  • Docs / chore

Notes

This changes historical migration source without changing supported database behavior: PostgreSQL executes the same backfill and partial index as before. Already-upgraded databases do not rerun revisions 114 or 115, while fresh installations continue to produce the same PostgreSQL schema and data state. No new Alembic revision is needed.

Application-model SQLite compatibility remains intact for ordinary unit tests.


Enterprise server image for this PR:

ghcr.io/openhands/enterprise-server:sha-7d40bba

@github-actions github-actions Bot added the type: chore Maintenance / chores label Jul 29, 2026
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ This PR contains migrations. Please synchronize before merging to prevent conflicts.

@github-actions

github-actions Bot commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Coverage report

This PR does not seem to contain any modification to coverable code.

@simonrosenberg
simonrosenberg marked this pull request as ready for review July 29, 2026 12:16
Comment thread AGENTS.md
Comment on lines +260 to +261
- Use SQLite in-memory databases (`sqlite:///:memory:`) for application unit tests instead of real PostgreSQL
- Do not add SQLite paths to enterprise Alembic migrations

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@saurya this seems a bit annoying? prod != tests?

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.

It makes sense!

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.

It's just too difficult to put up a whole Postgres database. SQLite serves as an adequate substitute for the purpose of quick testing.

@simonrosenberg
simonrosenberg requested a review from saurya July 29, 2026 15:09
@simonrosenberg simonrosenberg self-assigned this Jul 30, 2026
@simonrosenberg

Copy link
Copy Markdown
Member Author

@jlav do we really need SQLite for testing? even when its not used in prod?
This confuses AI agents that think SQLite is a prod possibility

@simonrosenberg
simonrosenberg enabled auto-merge (squash) August 3, 2026 08:36
@simonrosenberg
simonrosenberg merged commit 834dc4f into main Aug 3, 2026
19 checks passed
@simonrosenberg
simonrosenberg deleted the cleanup-postgresql-only-migrations branch August 3, 2026 08:49
@openhands-release-bot openhands-release-bot Bot added the released: 1.50.0 Shipped in 1.50.0 label Aug 6, 2026
@openhands-release-bot

Copy link
Copy Markdown
Contributor

🚀 Released in 1.50.0.

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

Labels

released: 1.50.0 Shipped in 1.50.0 type: chore Maintenance / chores

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants