Skip to content

Bump version to 6.0.0 and rename SQL scripts#401

Open
rasifr wants to merge 2 commits intomainfrom
task/SPOC-432/prepare-5.1.0-release
Open

Bump version to 6.0.0 and rename SQL scripts#401
rasifr wants to merge 2 commits intomainfrom
task/SPOC-432/prepare-5.1.0-release

Conversation

@rasifr
Copy link
Copy Markdown
Member

@rasifr rasifr commented Mar 27, 2026

Bump version to 6.0.0 and add upgrade path from 5.0.7

  • Update SPOCK_VERSION to "6.0.0" and SPOCK_VERSION_NUM to 60000 in include/spock.h
  • Rename spock--6.0.0-devel.sqlspock--6.0.0.sql and spock--5.0.6--6.0.0-devel.sqlspock--5.0.7--6.0.0.sql
  • Add spock--5.0.6--5.0.7.sql step upgrade script (pause/resume workers, wait_for_sync_event rewrite, sync_event optional transactional arg, sub_skip_schema column relabel)
  • Upgrade script drops obsolete functions, replaces progress/lag_tracker views, adds sub_id_generator sequence, migrates conflict type names, and adds cleanup_resolutions + subscription stats functions
  • Add TAP test 018_upgrade_schema_match to verify that a 5.0.7 → 6.0.0 upgrade produces a schema identical to a fresh 6.0.0 install

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 27, 2026

📝 Walkthrough

Walkthrough

This PR marks the Spock 6.0.0 release and introduces migration scripts for upgrading from Spock 5.0.6/5.0.7, alongside a comprehensive test suite validating schema equivalence after upgrade from 5.0.7 to 6.0.0.

Changes

Spock 6.0.0 Release & Upgrade Support

Layer / File(s) Summary
Migration Definitions
sql/spock--5.0.6--5.0.7.sql, sql/spock--5.0.7--6.0.0.sql
5.0.6→5.0.7 upgrade adds pause_apply_workers()/resume_apply_workers() functions, replaces wait_for_sync_event with polling procedures, and corrects sub_skip_schema catalog type to text[]. 5.0.7→6.0.0 upgrade drops obsolete conversion functions, removes deprecated sync_event/wait_for_sync_event, adds sub_alter_options() and wait_for_apply_worker(), and updates function attributes (IMMUTABLE PARALLEL SAFE).
Version Declaration
include/spock.h
SPOCK_VERSION macro updated from "6.0.0-devel" to "6.0.0".
Upgrade Schema Validation Test
tests/tap/t/018_upgrade_schema_match.pl
New TAP test verifies schema equivalence after 5.0.7→6.0.0 upgrade by comparing catalog entities (tables, columns, functions, views, sequences, function bodies) between an upgraded node and fresh 6.0.0 install. Supports fast-path reuse of pre-built PostgreSQL+Spock and full-path rebuilds from source.
Test Configuration
tests/tap/schedule, tests/regress/sql/init_fail.sql
Commented entry added for 018_upgrade_schema_match test in TAP schedule. Regression test init block updated to create extension at version 6.0.0 instead of 6.0.0-devel.

Poem

🐰 A devel string sheds its tail,
Six-point-oh goes on the trail,
Schemas dance from five to six,
Migrations blend their SQL mix,
Upgrade tales the test will tell! 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Title check ⚠️ Warning The title 'Bump version to 6.0.0 and rename SQL scripts' is misleading; the actual changes update the version to 6.0.0 in the version macro and test files, but the PR description indicates the intended version should be 5.1.0, creating a significant discrepancy between title and implementation. Clarify the version target (6.0.0 vs 5.1.0) and update the title to match the actual changes made in the PR.
✅ Passed checks (4 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed The description accurately describes the changeset: version bump to 6.0.0, SQL script renames, upgrade path additions from 5.0.7, and new TAP test for schema equivalence.

✏️ 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 task/SPOC-432/prepare-5.1.0-release

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.

@rasifr rasifr force-pushed the task/SPOC-432/prepare-5.1.0-release branch from 868f54b to 1cf3438 Compare March 28, 2026 10:32
@rasifr
Copy link
Copy Markdown
Member Author

rasifr commented Mar 30, 2026

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 30, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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.

🧹 Nitpick comments (1)
tests/tap/t/018_upgrade_schema_match.pl (1)

150-165: Minor: Temporary file cleanup on early exit.

If psql_query dies between creating $tmpfile and the unlink, the temp file is left behind. Consider using a block-scoped cleanup or wrapping in eval.

♻️ Suggested improvement
 sub psql_query {
     my ($port, $sql) = `@_`;
     my $tmpfile = "/tmp/spock_018_$$.sql";
+    my $out;
     open my $fh, '>', $tmpfile or die "Cannot write $tmpfile: $!";
     print $fh $sql;
     close $fh;
-    open $fh, '-|', "$PG_BIN/psql", '-X', '-t', '-A',
-        '-p', $port, '-d', $DB_NAME, '-U', $DB_USER, '-f', $tmpfile
-        or die "Cannot run psql: $!";
-    my $out = join '', <$fh>;
-    close $fh;
-    unlink $tmpfile;
+    eval {
+        open $fh, '-|', "$PG_BIN/psql", '-X', '-t', '-A',
+            '-p', $port, '-d', $DB_NAME, '-U', $DB_USER, '-f', $tmpfile
+            or die "Cannot run psql: $!";
+        $out = join '', <$fh>;
+        close $fh;
+    };
+    my $err = $@;
+    unlink $tmpfile;
+    die $err if $err;
     chomp $out;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/tap/t/018_upgrade_schema_match.pl` around lines 150 - 165, psql_query
currently writes a temp file and may leave it behind if the function dies before
the final unlink; modify psql_query to guarantee cleanup by using a safe
temporary-file helper (e.g., File::Temp->new or a block-scoped temp file) or
wrap the write/psql invocation in an eval/finally-like construct (local $@; eval
{ ... }; my $err = $@; unlink $tmpfile if -e $tmpfile; die $err if $err) so that
the temp file is always removed; reference the psql_query function and the
$tmpfile variable when making the change.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@tests/tap/t/018_upgrade_schema_match.pl`:
- Around line 150-165: psql_query currently writes a temp file and may leave it
behind if the function dies before the final unlink; modify psql_query to
guarantee cleanup by using a safe temporary-file helper (e.g., File::Temp->new
or a block-scoped temp file) or wrap the write/psql invocation in an
eval/finally-like construct (local $@; eval { ... }; my $err = $@; unlink
$tmpfile if -e $tmpfile; die $err if $err) so that the temp file is always
removed; reference the psql_query function and the $tmpfile variable when making
the change.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 87b0828a-fe94-4595-8692-810148ddddff

📥 Commits

Reviewing files that changed from the base of the PR and between a116148 and 1cf3438.

⛔ Files ignored due to path filters (2)
  • tests/regress/expected/init_1.out is excluded by !**/*.out
  • tests/regress/expected/init_fail.out is excluded by !**/*.out
📒 Files selected for processing (6)
  • include/spock.h
  • sql/spock--5.0.6--5.1.0.sql
  • sql/spock--5.1.0.sql
  • tests/regress/sql/init_fail.sql
  • tests/tap/schedule
  • tests/tap/t/018_upgrade_schema_match.pl

@rasifr rasifr marked this pull request as ready for review March 30, 2026 14:34
@mason-sharp mason-sharp changed the title Bump version to 5.1.0 and rename SQL scripts Bump version to 6.0.0 and rename SQL scripts Apr 27, 2026
@mason-sharp
Copy link
Copy Markdown
Member

We will also need to pull in 5.0.7

rasifr and others added 2 commits May 4, 2026 12:22
- Rename sql/spock--6.0.0-devel.sql → spock--6.0.0.sql
- Rename sql/spock--5.0.6--6.0.0-devel.sql → spock--5.0.7--6.0.0.sql
- Add sql/spock--5.0.6--5.0.7.sql step upgrade script
- Bump version in include/spock.h
- Update regression test fixtures for 6.0.0 version strings

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ma parity

TAP test that installs spock 5.0.7, upgrades to 6.0.0, and compares the
resulting schema against a fresh 6.0.0 install — covering tables, columns,
functions, views, sequences, view definitions, and function bodies.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@rasifr rasifr force-pushed the task/SPOC-432/prepare-5.1.0-release branch from 1cf3438 to e49aa36 Compare May 4, 2026 08:22
@codacy-production
Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 duplication

Metric Results
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

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: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@sql/spock--5.0.6--5.0.7.sql`:
- Line 37: Replace the invalid PL/pgSQL assignment-from-query "target_id :=
node_id FROM spock.node_info();" with a proper SELECT ... INTO form; e.g. use
"SELECT node_id INTO target_id FROM spock.node_info();" (or "SELECT INTO STRICT"
if you expect exactly one row) for both occurrences referencing target_id,
node_id and spock.node_info() (the instances around lines 37 and 109).

In `@tests/tap/t/018_upgrade_schema_match.pl`:
- Around line 276-280: The stop_pg helper ignores failures from pg_ctl which can
leave the old postmaster running; modify stop_pg (the function `stop_pg`) to
check the result/exit status of `run_logged("$PG_BIN/pg_ctl", 'stop', ...)` and
fail the test (or die) if pg_ctl returns non-zero, and optionally wait/retry
until the postmaster is confirmed stopped (e.g. poll for PID file removal or use
`pg_ctl status`) before returning so subsequent phase 6 upgrade assertions won't
run against a still-running old postmaster.
- Around line 156-161: The current code reads psql output from a piped
filehandle ($fh) but never checks the exit status of the spawned psql process,
which can return non-zero and produce empty output; after close $fh add a check
of the child's exit status (e.g., inspect $? and die with a clear error
including $tmpfile, the command and exit code) so that when the psql invocation
(the open using "$PG_BIN/psql" with $tmpfile) fails the test fails fast instead
of using empty output for schema matching.
🪄 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: 99ba0d47-b3ac-43ef-b218-8c30016e8fcb

📥 Commits

Reviewing files that changed from the base of the PR and between 1cf3438 and e49aa36.

⛔ Files ignored due to path filters (2)
  • tests/regress/expected/init_1.out is excluded by !**/*.out
  • tests/regress/expected/init_fail.out is excluded by !**/*.out
📒 Files selected for processing (7)
  • include/spock.h
  • sql/spock--5.0.6--5.0.7.sql
  • sql/spock--5.0.7--6.0.0.sql
  • sql/spock--6.0.0.sql
  • tests/regress/sql/init_fail.sql
  • tests/tap/schedule
  • tests/tap/t/018_upgrade_schema_match.pl
✅ Files skipped from review due to trivial changes (2)
  • include/spock.h
  • tests/tap/schedule

IF origin_id IS NULL THEN
RAISE EXCEPTION 'Invalid NULL origin_id';
END IF;
target_id := node_id FROM spock.node_info();
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 | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Expect no matches after the fix.
rg -nP ':\=\s*[A-Za-z_][A-Za-z0-9_]*\s+FROM\s+' sql/spock--5.0.6--5.0.7.sql

Repository: pgEdge/spock

Length of output: 173


🏁 Script executed:

cat -n sql/spock--5.0.6--5.0.7.sql | head -50

Repository: pgEdge/spock

Length of output: 2380


🏁 Script executed:

cat -n sql/spock--5.0.6--5.0.7.sql | sed -n '25,50p'

Repository: pgEdge/spock

Length of output: 1133


🏁 Script executed:

cat -n sql/spock--5.0.6--5.0.7.sql | sed -n '100,120p'

Repository: pgEdge/spock

Length of output: 937


Fix invalid PL/pgSQL assignment-from-query syntax at lines 37 and 109.

The := ... FROM ... construct is not valid PL/pgSQL and will fail when the procedures are created during the upgrade.

Proposed fix
-	target_id := node_id FROM spock.node_info();
+	SELECT node_id INTO target_id FROM spock.node_info();
-	origin_id := node_id FROM spock.node WHERE node_name = origin;
+	SELECT node_id INTO origin_id FROM spock.node WHERE node_name = origin;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
target_id := node_id FROM spock.node_info();
SELECT node_id INTO target_id FROM spock.node_info();
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@sql/spock--5.0.6--5.0.7.sql` at line 37, Replace the invalid PL/pgSQL
assignment-from-query "target_id := node_id FROM spock.node_info();" with a
proper SELECT ... INTO form; e.g. use "SELECT node_id INTO target_id FROM
spock.node_info();" (or "SELECT INTO STRICT" if you expect exactly one row) for
both occurrences referencing target_id, node_id and spock.node_info() (the
instances around lines 37 and 109).

Comment on lines +156 to +161
open $fh, '-|', "$PG_BIN/psql", '-X', '-t', '-A',
'-p', $port, '-d', $DB_NAME, '-U', $DB_USER, '-f', $tmpfile
or die "Cannot run psql: $!";
my $out = join '', <$fh>;
close $fh;
unlink $tmpfile;
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 | ⚡ Quick win

Fail fast when psql_query execution fails.

Line 156–Line 161 do not validate the piped psql exit status. A failed query can collapse to empty output and produce false-positive schema matches.

💡 Proposed fix
     my $out = join '', <$fh>;
-    close $fh;
+    my $ok = close $fh;
+    my $rc = $? >> 8;
     unlink $tmpfile;
+    die "psql query failed (rc=$rc) for $tmpfile" if !$ok || $rc != 0;
     chomp $out;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/tap/t/018_upgrade_schema_match.pl` around lines 156 - 161, The current
code reads psql output from a piped filehandle ($fh) but never checks the exit
status of the spawned psql process, which can return non-zero and produce empty
output; after close $fh add a check of the child's exit status (e.g., inspect $?
and die with a clear error including $tmpfile, the command and exit code) so
that when the psql invocation (the open using "$PG_BIN/psql" with $tmpfile)
fails the test fails fast instead of using empty output for schema matching.

Comment on lines +276 to +280
sub stop_pg {
my ($datadir) = @_;
run_logged("$PG_BIN/pg_ctl", 'stop', '-D', $datadir, '-m', 'fast', '-w');
sleep 2;
}
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 | ⚡ Quick win

Check pg_ctl stop result before continuing upgrade flow.

Line 276–Line 280 ignore stop failures; Phase 6 may continue with an old postmaster still running, making the binary-swap/version assertions flaky.

💡 Proposed fix
 sub stop_pg {
     my ($datadir) = `@_`;
-    run_logged("$PG_BIN/pg_ctl", 'stop', '-D', $datadir, '-m', 'fast', '-w');
+    my $rc = run_logged("$PG_BIN/pg_ctl", 'stop', '-D', $datadir, '-m', 'fast', '-w');
+    BAIL_OUT("Failed to stop postgres datadir=$datadir (rc=$rc). See $LOG_FILE") if $rc;
     sleep 2;
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
sub stop_pg {
my ($datadir) = @_;
run_logged("$PG_BIN/pg_ctl", 'stop', '-D', $datadir, '-m', 'fast', '-w');
sleep 2;
}
sub stop_pg {
my ($datadir) = `@_`;
my $rc = run_logged("$PG_BIN/pg_ctl", 'stop', '-D', $datadir, '-m', 'fast', '-w');
BAIL_OUT("Failed to stop postgres datadir=$datadir (rc=$rc). See $LOG_FILE") if $rc;
sleep 2;
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/tap/t/018_upgrade_schema_match.pl` around lines 276 - 280, The stop_pg
helper ignores failures from pg_ctl which can leave the old postmaster running;
modify stop_pg (the function `stop_pg`) to check the result/exit status of
`run_logged("$PG_BIN/pg_ctl", 'stop', ...)` and fail the test (or die) if pg_ctl
returns non-zero, and optionally wait/retry until the postmaster is confirmed
stopped (e.g. poll for PID file removal or use `pg_ctl status`) before returning
so subsequent phase 6 upgrade assertions won't run against a still-running old
postmaster.

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.

2 participants