fix: replace generated column with partial unique index for PG logical replication - #39473
fix: replace generated column with partial unique index for PG logical replication#39473rkfshakti wants to merge 4 commits into
Conversation
Pyrefly Type Coverage
|
rkfshakti
left a comment
There was a problem hiding this comment.
please review to share feedback, this should be resolved now.
|
Friendly ping — this PR has been open for a few days with CI passing. The fix replaces a generated column on the agents table with a partial unique index so PostgreSQL logical replication doesn't fail with InvalidColumnReference. As @crazywoola noted on #39472, there's an overlapping migration file between these two PRs — I'm happy to consolidate them into a single PR if that's preferred. Let me know how you'd like to proceed. |
…l replication The agents table had a STORED GENERATED column (roster_unique_name) in a UniqueConstraint. When PostgreSQL has wal_level=logical (logical replication enabled), it tries to use this unique constraint for replica identity tracking, but generated columns cannot be published, causing: InvalidColumnReference: cannot update table 'agents' DETAIL: Replica identity must not contain unpublished generated columns. Replace the generated column + unique constraint with a partial unique index on (tenant_id, name) WHERE scope='roster' AND status='active'. This achieves the same uniqueness guarantee without a generated column. Fixes langgenius#39460
… column The tests were still checking for the old UniqueConstraint (agents_tenant_id_key) and the roster_unique_name generated column, which were replaced with a partial unique index to fix PostgreSQL logical replication conflicts. Update test_agent_table_uses_partial_unique_index_for_active_roster_names to verify the new partial unique index (agents_tenant_id_active_roster_name_key) with its postgresql_where condition. Update test_active_roster_agent_name_unique_constraint_allows_archived_and_workflow_only_duplicates to verify the schema definition instead of runtime enforcement, since SQLite does not support postgresql_where partial indexes.
ColumnCollection does not compare equal to a plain tuple, causing AssertionError. Use the same tuple(column.name ...) pattern as the roster index assertion.
b0f18b2 to
8dfa12c
Compare
|
Hi maintainers — following up again on this fix for #39460. Replaces the generated column with a partial unique index for PostgreSQL logical replication compatibility. CI is passing. Would appreciate a review when time allows. Thanks! |
When PostgreSQL has wal_level=logical (logical replication enabled), the agents table's STORED GENERATED column (roster_unique_name) in a UniqueConstraint causes:
InvalidColumnReference: cannot update table 'agents'
DETAIL: Replica identity must not contain unpublished generated columns.
Replace the generated column + unique constraint with a partial unique index on (tenant_id, name) WHERE scope='roster' AND status='active'. This achieves the same uniqueness guarantee without a generated column.
Fixes #39460