Skip to content

Prepare v2.0.0#113

Closed
mason-sharp wants to merge 2 commits intomainfrom
prepare-v2.0.0
Closed

Prepare v2.0.0#113
mason-sharp wants to merge 2 commits intomainfrom
prepare-v2.0.0

Conversation

@mason-sharp
Copy link
Copy Markdown
Member

Also update the native PG test to verify origin tracking

Extend PG test to connect to all three nodes. The new test sets up
n3 → n1/n2 logical replication, verifies origin tracking through
GetNodeOriginNames, then runs a full diff + preserve-origin repair
cycle confirming both origins and timestamps are preserved.
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 19, 2026

📝 Walkthrough

Walkthrough

Added a third PostgreSQL node (native-n3) to the integration test infrastructure and refactored the testNativePreserveOrigin test to validate a 3-node replication topology with origin preservation. Updated the changelog to document v2.0.0 features related to native PostgreSQL mode.

Changes

Cohort / File(s) Summary
Documentation
docs/CHANGELOG.md
Added v2.0.0 changelog entry documenting native PostgreSQL mode support, per-node Spock detection, replication-origin/slot LSN queries, SQL identifier sanitization, and bug fixes for concurrency and subscription matching issues.
Test Infrastructure
tests/integration/docker-compose-native.yaml
Added a new native-n3 PostgreSQL 17 service with matching configuration to existing nodes (native-n1/native-n2), including user, password, database, and required flags for commit timestamp tracking and logical replication.
Native PostgreSQL Testing
tests/integration/native_pg_test.go
Extended test cluster setup to support a third node (native-n3) with generalized port-waiting logic; refactored testNativePreserveOrigin from 2-node to 3-node topology with subscriptions on multiple nodes and enhanced origin/timestamp preservation validation.

Poem

🐰 Three nodes now dance in perfect sync,
Native PostgreSQL spreads its ink,
No Spock extension needed here,
Origin-tracked repairs crystal clear!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Prepare v2.0.0' directly summarizes the main change—preparing a v2.0.0 release with documentation and test updates as shown in the changeset.
Description check ✅ Passed The description 'Also update the native PG test to verify origin tracking' is related to the changeset, referencing the test updates in native_pg_test.go.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch prepare-v2.0.0

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codacy-production
Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 8 complexity · -4 duplication

Metric Results
Complexity 8
Duplication -4

View in Codacy

TIP This summary will be updated as you push new changes. Give us feedback

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
tests/integration/native_pg_test.go (1)

609-617: ⚠️ Potential issue | 🟡 Minor

Use SET LOCAL to constrain session_replication_role to this transaction.

SET session_replication_role = 'replica' without LOCAL is session-scoped; with pgxpool, the connection returns to the pool still in replica mode after Commit, potentially affecting subsequent operations. Use SET LOCAL and add a rollback defer for failure paths.

Proposed fix
 tx, err := state.n2Pool.Begin(ctx)
 require.NoError(t, err)
+defer tx.Rollback(ctx) // ignored after successful commit
-_, err = tx.Exec(ctx, "SET session_replication_role = 'replica'")
+_, err = tx.Exec(ctx, "SET LOCAL session_replication_role = 'replica'")
 require.NoError(t, err)
 for _, id := range sampleIDs {
 	_, err = tx.Exec(ctx, fmt.Sprintf("DELETE FROM %s WHERE id = $1", qualifiedTableName), id)
 	require.NoError(t, err)
 }
 require.NoError(t, tx.Commit(ctx))
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/integration/native_pg_test.go` around lines 609 - 617, The transaction
sets session_replication_role globally which can leak into pooled connections;
change the statement executed on the tx returned by state.n2Pool.Begin(ctx) to
use "SET LOCAL session_replication_role = 'replica'" so it only applies to that
transaction, and add a defer to rollback the tx on early returns/errors (e.g.
defer func(){ _ = tx.Rollback(ctx) }()) before looping over sampleIDs and before
committing with tx.Commit(ctx) to ensure the tx is cleaned up on failures;
update references in the failing block that use tx, qualifiedTableName,
sampleIDs, and tx.Commit accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@docs/CHANGELOG.md`:
- Around line 21-24: Update the CHANGELOG entry to accurately state that ACE
schema names are sanitized in Go before template rendering: change the wording
so it says the schema name is sanitized by the aceSchema() Go function (used by
CreateSchema) prior to being passed into the SQL template (the template still
renders {{.SchemaName}} without calling .Sanitize()); reference aceSchema() in
internal/consistency/mtree/merkle.go and the CreateSchema template in
db/queries/templates.go to ensure the note correctly attributes where
sanitization occurs.

In `@tests/integration/native_pg_test.go`:
- Around line 655-663: The test currently only checks repairedOrigin is
non-empty; change it to assert the preserved origin equals the expected
normalized origin. For each id in sampleIDs call getNativeReplicationOrigin(t,
ctx, state.n2Pool, qualifiedTableName, id), compute the expected origin (e.g.
subN1Name or the exact value from your diff metadata/ originalOrigins[id] after
any normalization you apply), and replace require.NotEmpty with require.Equal(t,
expectedOrigin, repairedOrigin, ...) so the test verifies the exact preserved
origin rather than any non-empty value. Ensure you reference repairedOrigin,
originalOrigins, subN1Name, getNativeReplicationOrigin, qualifiedTableName, and
state.n2Pool when locating code to change.

---

Outside diff comments:
In `@tests/integration/native_pg_test.go`:
- Around line 609-617: The transaction sets session_replication_role globally
which can leak into pooled connections; change the statement executed on the tx
returned by state.n2Pool.Begin(ctx) to use "SET LOCAL session_replication_role =
'replica'" so it only applies to that transaction, and add a defer to rollback
the tx on early returns/errors (e.g. defer func(){ _ = tx.Rollback(ctx) }())
before looping over sampleIDs and before committing with tx.Commit(ctx) to
ensure the tx is cleaned up on failures; update references in the failing block
that use tx, qualifiedTableName, sampleIDs, and tx.Commit accordingly.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4ade17d0-bcbf-49ce-a4f7-5fd3e4368771

📥 Commits

Reviewing files that changed from the base of the PR and between 16354d3 and 278e745.

📒 Files selected for processing (3)
  • docs/CHANGELOG.md
  • tests/integration/docker-compose-native.yaml
  • tests/integration/native_pg_test.go

Comment thread docs/CHANGELOG.md
Comment on lines +21 to +24
### Changed
- ACE schema name in SQL templates is now quoted with `pgx.Identifier.Sanitize()`
to prevent SQL breakage with non-simple schema names (e.g., mixed case,
hyphens).
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Description: Verify whether ACE schema creation/template paths sanitize schema identifiers.

rg -n -C3 'CreateSchema\(|aceSchema\(\)|pgx\.Identifier|\.Sanitize\(\)' --type go

Repository: pgEdge/ace

Length of output: 50366


🏁 Script executed:

fd -e sql -o -e tmpl -o -e tpl | head -20

Repository: pgEdge/ace

Length of output: 170


🏁 Script executed:

find . -name "*.sql" -o -name "*.tmpl" -o -name "*template*" | grep -v node_modules | head -30

Repository: pgEdge/ace

Length of output: 102


🏁 Script executed:

rg -l "CREATE SCHEMA|CreateSchema" --type sql --type tmpl --max-count 20

Repository: pgEdge/ace

Length of output: 82


🏁 Script executed:

cat -n db/queries/templates.go | head -100

Repository: pgEdge/ace

Length of output: 5019


🏁 Script executed:

rg -n "CreateSchema|GetCreateSchema" db/queries/

Repository: pgEdge/ace

Length of output: 512


🏁 Script executed:

sed -n '1510,1520p' db/queries/templates.go

Repository: pgEdge/ace

Length of output: 585


Clarify the scope of identifier sanitization in the release notes.

The CHANGELOG claim is inaccurate. The ACE schema name is sanitized via the aceSchema() Go function before being passed to CreateSchema, not within the SQL template itself. The CreateSchema SQL template (line 1510 in db/queries/templates.go) renders {{.SchemaName}} without calling .Sanitize(). While the final schema name is quoted (because m.aceSchema() at line 819 in internal/consistency/mtree/merkle.go returns a pre-sanitized string), the sanitization happens in Go code, not "in SQL templates" as the release note suggests. Revise line 22 to clarify that the schema name is now sanitized before SQL template rendering, not within the templates themselves.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/CHANGELOG.md` around lines 21 - 24, Update the CHANGELOG entry to
accurately state that ACE schema names are sanitized in Go before template
rendering: change the wording so it says the schema name is sanitized by the
aceSchema() Go function (used by CreateSchema) prior to being passed into the
SQL template (the template still renders {{.SchemaName}} without calling
.Sanitize()); reference aceSchema() in internal/consistency/mtree/merkle.go and
the CreateSchema template in db/queries/templates.go to ensure the note
correctly attributes where sanitization occurs.

Comment on lines +655 to +663
// --- Verify origins are preserved ---
// After preserve-origin repair, repaired rows on n2 should have an
// ACE-created origin that encodes the original source (n3 via n1).
for _, id := range sampleIDs {
repairedOrigin := getNativeReplicationOrigin(t, ctx, state.n2Pool, qualifiedTableName, id)
require.NotEmpty(t, repairedOrigin,
"Row %d should have a replication origin after preserve-origin repair", id)
log.Printf("Row %d: n1 origin=%s, repaired n2 origin=%s", id, originalOrigins[id], repairedOrigin)
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Assert the preserved origin, not just that some origin exists.

This passes if repair writes any non-empty replication origin, so it does not verify the PR’s preserve-origin invariant. Compare repairedOrigin to the expected normalized origin, such as subN1Name or the exact value emitted in the diff metadata, instead of only logging originalOrigins[id].

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/integration/native_pg_test.go` around lines 655 - 663, The test
currently only checks repairedOrigin is non-empty; change it to assert the
preserved origin equals the expected normalized origin. For each id in sampleIDs
call getNativeReplicationOrigin(t, ctx, state.n2Pool, qualifiedTableName, id),
compute the expected origin (e.g. subN1Name or the exact value from your diff
metadata/ originalOrigins[id] after any normalization you apply), and replace
require.NotEmpty with require.Equal(t, expectedOrigin, repairedOrigin, ...) so
the test verifies the exact preserved origin rather than any non-empty value.
Ensure you reference repairedOrigin, originalOrigins, subN1Name,
getNativeReplicationOrigin, qualifiedTableName, and state.n2Pool when locating
code to change.

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.

1 participant