Skip to content

Auto-include partition columns in unique indexes (GH-3557)#4139

Merged
jeremydmiller merged 1 commit intomasterfrom
GH3557
Feb 16, 2026
Merged

Auto-include partition columns in unique indexes (GH-3557)#4139
jeremydmiller merged 1 commit intomasterfrom
GH3557

Conversation

@jeremydmiller
Copy link
Member

Summary

  • Fixes Add functionality to allow custom indexes with multiple fields including meta data  #3557 - PostgreSQL requires unique indexes on partitioned tables to include all partitioning columns
  • Adds logic in Weasel's IndexDefinition.correctedExpression() to automatically append any missing partition columns when generating DDL for unique indexes on partitioned tables
  • Uses a local Weasel project reference with the fix (the Weasel change needs to be published as a new package version before merging)

Weasel Change

The core fix is in Weasel's IndexDefinition.cs (correctedExpression(Table? parent)). When IsUnique and the parent table has a Partitioning strategy, any partition columns not already present in the index's Columns are appended to the index expression. The Weasel commit is on branch GH3557-unique-index-partitioning at ~/code/weasel.

Tests Added

  • unique_index_on_partitioned_table_includes_partition_columns_in_ddl - DDL includes tenant_id for hash-partitioned table
  • unique_index_on_soft_delete_partitioned_table_includes_partition_columns_in_ddl - DDL includes mt_deleted for soft-delete partitioned table
  • unique_index_does_not_duplicate_partition_columns_already_present - No duplication when partition column already in index via TenancyScope.PerTenant
  • unique_index_on_partitioned_table_can_be_applied_to_database - Integration test applying schema to PostgreSQL

Test plan

  • All 25 partitioning tests pass
  • All 6 unique index tests pass
  • All 8 multi-tenancy partitioning tests pass
  • Weasel change needs to be committed/published separately before switching back to NuGet reference

🤖 Generated with Claude Code

Use Weasel project reference with fix that auto-includes partition columns
in unique index DDL. Add tests verifying partition columns are included for
multi-tenant and soft-delete partitioning, no duplication when already present,
and successful schema application to PostgreSQL.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

Add functionality to allow custom indexes with multiple fields including meta data

1 participant