Skip to content

Conversation

@eminano
Copy link
Collaborator

@eminano eminano commented Jan 13, 2026

Description

This PR updates the replication logic to flag the schema being dropped in the schema diff, and replicating it downstream to Postgres targets. Currently schema drops were ignored in the target.

Related Issue(s)

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)

Testing

  • Unit tests added/updated
  • Integration tests added/updated
  • Manual testing performed
  • All existing tests pass

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds support for replicating schema drop operations to Postgres targets. Previously, schema drops were ignored during replication. The changes introduce a SchemaDropped flag in the schema diff structure and ensure that when a schema is marked as dropped, a DROP SCHEMA IF EXISTS ... CASCADE query is generated and executed on the target.

Changes:

  • Added SchemaDropped field to the Diff struct in the schema diff logic
  • Updated ComputeSchemaDiff to detect when a schema is dropped and set the flag
  • Modified the Postgres adapter to generate DROP SCHEMA queries when SchemaDropped is true
  • Added test coverage for schema drop handling in the DDL adapter tests

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
pkg/schemalog/schema_diff.go Added SchemaDropped field to Diff struct, updated IsEmpty() check, and added logic in ComputeSchemaDiff to detect schema drops
pkg/wal/processor/postgres/postgres_wal_ddl_adapter.go Refactored schemaLogToQueries to remove unconditional CREATE SCHEMA, added DROP SCHEMA generation when SchemaDropped is true
pkg/wal/processor/postgres/postgres_wal_ddl_adapter_test.go Added test case for schema dropped scenario, updated all existing test cases to expect CREATE SCHEMA query

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@eminano eminano requested a review from exekias January 13, 2026 11:41
@github-actions
Copy link

Merging this branch will increase overall coverage

Impacted Packages Coverage Δ 🤖
github.com/xataio/pgstream/pkg/schemalog 52.39% (+0.65%) 👍
github.com/xataio/pgstream/pkg/wal/processor/postgres 81.86% (+0.11%) 👍

Coverage by file

Changed files (no unit tests)

Changed File Coverage Δ Total Covered Missed 🤖
github.com/xataio/pgstream/pkg/schemalog/schema_diff.go 92.73% (+0.75%) 165 (+3) 153 (+4) 12 (-1) 👍
github.com/xataio/pgstream/pkg/wal/processor/postgres/postgres_wal_ddl_adapter.go 90.99% (+0.39%) 233 (-1) 212 21 (-1) 👍

Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code.

Changed unit test files

  • github.com/xataio/pgstream/pkg/schemalog/schema_diff_test.go
  • github.com/xataio/pgstream/pkg/wal/processor/postgres/postgres_wal_ddl_adapter_test.go

@eminano eminano merged commit 5d3df83 into main Jan 13, 2026
7 checks passed
@eminano eminano deleted the fix-schema-drop-not-replicated branch January 13, 2026 12:03
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.

[Postgres target] Schema drop not being replicated to the target

3 participants