fix: preserve manually-created partial indexes when partialIndexes preview feature is disabled#5790
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughAdds preview-feature-aware handling for partial-index predicates: predicates are stripped and tracked when Changes
Possibly related issues
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 082c92c9-4a0d-4f11-b6b1-7426f8a9499b
📒 Files selected for processing (5)
schema-engine/connectors/sql-schema-connector/src/lib.rsschema-engine/connectors/sql-schema-connector/src/sql_schema_differ/table.rsschema-engine/sql-migration-tests/tests/migrations/indexes/partial.rsschema-engine/sql-schema-describer/src/lib.rsschema-engine/sql-schema-describer/src/walkers/index.rs
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 6deb0f99-1de8-4cf6-88cc-f64ef6aff53e
📒 Files selected for processing (1)
schema-engine/sql-schema-describer/src/lib.rs
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 0788a199-39b6-4287-b65e-126eeba11095
📒 Files selected for processing (7)
schema-engine/commands/src/commands/diagnose_migration_history.rsschema-engine/commands/src/commands/diff.rsschema-engine/connectors/mongodb-schema-connector/src/lib.rsschema-engine/connectors/schema-connector/src/schema_connector.rsschema-engine/connectors/sql-schema-connector/src/lib.rsschema-engine/sql-migration-tests/tests/migrations/diagnose_migration_history_tests.rsschema-engine/sql-migration-tests/tests/migrations/diff.rs
…e preview features to diff paths
There was a problem hiding this comment.
Actionable comments posted: 4
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
schema-engine/sql-migration-tests/src/test_api.rs (1)
221-227:⚠️ Potential issue | 🟠 MajorPass the active preview-feature set into
diff_cli().Line 225 hard-codes
BitFlags::empty(), so this helper always drives the diff CLI down the "feature disabled" path.TestApialready tracks preview features later in this file (Lines 596-607), so tests that enable a preview feature can silently exercise the wrong diff behavior here.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: e5fd1dd1-2d9f-4127-a687-7d6214d9f840
📒 Files selected for processing (12)
schema-engine/commands/src/commands/diff.rsschema-engine/core/src/commands/diff_cli.rsschema-engine/core/src/state.rsschema-engine/sql-migration-tests/src/test_api.rsschema-engine/sql-migration-tests/tests/migrations/diff.rsschema-engine/sql-schema-describer/src/feature_gated_partial_indexes.rsschema-engine/sql-schema-describer/src/lib.rsschema-engine/sql-schema-describer/tests/describers/mssql_describer_tests.rsschema-engine/sql-schema-describer/tests/describers/mysql_describer_tests.rsschema-engine/sql-schema-describer/tests/describers/postgres_describer_tests.rsschema-engine/sql-schema-describer/tests/describers/postgres_describer_tests/cockroach_describer_tests.rsschema-engine/sql-schema-describer/tests/describers/sqlite_describer_tests.rs
schema-engine/sql-schema-describer/src/feature_gated_partial_indexes.rs
Outdated
Show resolved
Hide resolved
schema-engine/sql-schema-describer/tests/describers/postgres_describer_tests.rs
Outdated
Show resolved
Hide resolved
…es and add engine-seeded diff test
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
schema-engine/connectors/sql-schema-connector/src/sql_schema_differ/table.rs (1)
63-69:⚠️ Potential issue | 🟠 MajorIgnore stripped partials in all index matching paths, not just drops.
Line 68 only fixes the drop path.
created_indexes()andindex_pairs()still consume stripped partial indexes throughprevious_indexes()/next_indexes(), and once the predicate has been nulled they can be matched as ordinary indexes. That can turn a manual partial index into a false “already exists” or rename candidate instead of ignoring it.Suggested fix
pub fn dropped_indexes<'a>(&'a self) -> impl Iterator<Item = IndexWalker<'schema>> + 'a { self.previous_indexes().filter(move |previous_index| { !self .next_indexes() .any(|next_index| indexes_match(*previous_index, next_index, self.db.flavour)) - && !previous_index.is_stripped_partial() }) } fn previous_indexes(&self) -> impl Iterator<Item = IndexWalker<'schema>> { - self.previous().indexes().filter(|idx| !idx.is_primary_key()) + self.previous() + .indexes() + .filter(|idx| !idx.is_primary_key() && !idx.is_stripped_partial()) } fn next_indexes(&self) -> impl Iterator<Item = IndexWalker<'schema>> { - self.next().indexes().filter(|idx| !idx.is_primary_key()) + self.next() + .indexes() + .filter(|idx| !idx.is_primary_key() && !idx.is_stripped_partial()) }
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 2d7bbb17-1ea9-46a9-a86d-2e7d0d97a445
📒 Files selected for processing (11)
schema-engine/connectors/sql-schema-connector/src/lib.rsschema-engine/connectors/sql-schema-connector/src/sql_schema_differ/table.rsschema-engine/sql-migration-tests/tests/migrations/diff.rsschema-engine/sql-schema-describer/src/lib.rsschema-engine/sql-schema-describer/src/stripped_partial_indexes.rsschema-engine/sql-schema-describer/src/walkers/index.rsschema-engine/sql-schema-describer/tests/describers/mssql_describer_tests.rsschema-engine/sql-schema-describer/tests/describers/mysql_describer_tests.rsschema-engine/sql-schema-describer/tests/describers/postgres_describer_tests.rsschema-engine/sql-schema-describer/tests/describers/postgres_describer_tests/cockroach_describer_tests.rsschema-engine/sql-schema-describer/tests/describers/sqlite_describer_tests.rs
schema-engine/sql-schema-describer/tests/describers/mysql_describer_tests.rs
Show resolved
Hide resolved
|
@coderabbitai resume |
✅ Actions performedReviews resumed. |
|
Hi @jacek-prisma. Please review these changes! Thank you. |
Note:
The issue is that stripped partial indexes must still participate in existence matching so the differ recognizes "an index with these columns already exists" and skips The correct behavior is:
|
Merging this PR will not alter performance
Comparing Footnotes
|
Fixes #5789 and prisma/prisma#29289
Problem
#5780 stripped partial index predicates when
partialIndexesis disabled, but manually-created partial indexes were still dropped as drift.Solution
SqlSchema::feature_gated_partial_indexesdropped_indexesin the differChanges
sql-schema-describer: Addedfeature_gated_partial_indexes: HashSet<IndexId>to track stripped indexessql-schema-connector: Skip feature-gated partial indexes indropped_indexesSummary by CodeRabbit
Bug Fixes
New Features
Tests