Skip to content

Preserve partial index predicates in migrations#31

Merged
mr-fatalyst merged 1 commit into
mr-fatalyst:mainfrom
ebrake:origin/fix/migration-fix-partial
May 8, 2026
Merged

Preserve partial index predicates in migrations#31
mr-fatalyst merged 1 commit into
mr-fatalyst:mainfrom
ebrake:origin/fix/migration-fix-partial

Conversation

@ebrake

@ebrake ebrake commented May 7, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Preserve Index(where=...) predicates in migration schema snapshots.
  • Carry partial-index predicates through Rust migration metadata and generated migration SQL.
  • Emit partial-index SQL for PostgreSQL and SQLite.
  • Reject MySQL partial indexes with a clear error instead of silently dropping predicates.
  • Detect changed index definitions by rebuilding the index.

Tests Added

  • Added a focused schema extraction regression test; verifies Index(where=...) survives extract_current_schema()

    • test_extract_partial_index_where_in_snapshot
  • Added Python migration SQL coverage; verifies PostgreSQL/SQLite render WHERE ... and MySQL raises a clear unsupported-dialect error.

    • test_create_partial_index
    • test_create_partial_index_mysql_rejected
  • Added full Python migration pipeline coverage; verifies model -> snapshot -> diff -> generated migration -> SQL keeps the partial-index predicate.

    • test_create_partial_index_preserves_where
  • Added Rust migration diff and SQL coverage; verifies predicate changes rebuild indexes, whitespace-only differences are ignored, partial-index SQL is emitted for supported dialects, and JSON round-tripping preserves normalized predicates.

    • test_compute_diff_detects_partial_index_predicate_change
    • test_compute_diff_ignores_partial_index_predicate_whitespace
    • test_partial_index_sql
    • test_partial_index_json_roundtrip_trims_predicate

Fixes #30

@ebrake ebrake changed the title Preserve partial index predicates in migrations #30 Preserve partial index predicates in migrations May 7, 2026
@mr-fatalyst mr-fatalyst merged commit 3f83f97 into mr-fatalyst:main May 8, 2026
5 checks passed
@ebrake ebrake deleted the origin/fix/migration-fix-partial branch May 14, 2026 13:23
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.

Index(where=...) is dropped from migration snapshots, so makemigrations cannot generate partial indexes

2 participants