Skip to content

fix(persistence): compile dialect-safe boolean defaults - #2087

Merged
RaghavChamadiya merged 1 commit into
repowise-dev:mainfrom
justonemorenight:codex/fix-postgres-boolean-defaults
Sep 5, 2026
Merged

RaghavChamadiya merged 1 commit into
repowise-dev:mainfrom
justonemorenight:codex/fix-postgres-boolean-defaults

Conversation

@justonemorenight

Copy link
Copy Markdown
Contributor

Summary

  • compile Python boolean defaults as typed SQLAlchemy literals for the active database dialect
  • emit 0/1 for SQLite and false/true for PostgreSQL during additive column reconciliation
  • cover both boolean values on both supported dialects

This fixes legacy PostgreSQL upgrades for every model Boolean backed only by a Python default, including both conversations.pinned and coverage_files.mapping_partial.

Related Issues

Fixes #2059

Test Plan

  • uv run pytest -q tests/unit/persistence/test_schema_reconciliation.py (13 passed)
  • uv run ruff check packages/core/src/repowise/core/persistence/database.py tests/unit/persistence/test_schema_reconciliation.py
  • git diff --check

Risk

Repowise change risk: 18th percentile (Below typical / low review priority). Numeric and string defaults retain their existing rendering; only Python bool defaults use the dialect compiler.

Why:
- Additive PostgreSQL reconciliation rejected integer defaults for missing BOOLEAN columns.

Changes:
- Compile Python boolean defaults as typed SQLAlchemy literals for the active dialect.
- Cover false and true defaults on SQLite and PostgreSQL dialects.

Testing:
- uv run pytest -q tests/unit/persistence/test_schema_reconciliation.py
- uv run ruff check packages/core/src/repowise/core/persistence/database.py tests/unit/persistence/test_schema_reconciliation.py
- git diff --check

@RaghavChamadiya RaghavChamadiya left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Right fix in the right place. Compiling the typed literal against the dialect is what _add_column_ddl should have been doing from the start: bool is not int in PostgreSQL, and DEFAULT 0 on a BOOLEAN column is a syntax error there, so the legacy-column path could not add a boolean column to a Postgres index at all. The parametrized test pinning 0/1 on SQLite and false/true on Postgres is the assertion I would have asked for.

Non-blocking: the diff carries two formatting-only hunks (the blank line at database.py:46 and the f-string reflow in the _run lambda) that are not part of the fix. Not worth another round trip, but this repo does not run ruff format over the tree, so please keep future diffs to the change itself.

@RaghavChamadiya
RaghavChamadiya merged commit 926540c into repowise-dev:main Sep 5, 2026
8 checks passed
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.

[Bug] PostgreSQL schema reconciliation emits integer defaults for Boolean columns

2 participants