Skip to content

Commit 1847644

Browse files
jrgemignaniclaude
andauthored
Improve extension upgrade regression test (addendum to #2364) (#2377)
Note: This PR was created with AI tools and a human. This is an addendum to PR #2364 with three improvements. Makefile: - Replace awk-based synthetic version (minor+1) with an _upgrade_test suffix (e.g., 1.7.0 -> 1.7.0_upgrade_test). The awk approach produced numeric versions like 1.8.0 that could collide with real future upgrade scripts, and the ::int[] cast in the SQL version lookup fails on non-numeric version strings. The _upgrade_test suffix avoids both issues and is unambiguously synthetic. - Extend the generated cleanup script to also remove repo-root copies of the synthetic files and to self-delete, preventing stale artifacts from accumulating across repeated test runs. Regression test (regress/sql/age_upgrade.sql): - Simplify version lookup to directly select the _upgrade_test version via LIKE '%_upgrade_test' instead of picking the highest non-default version with string_to_array(version, '.')::int[] DESC. The old approach would fail with a cast error on the _upgrade_test suffix and was unnecessarily indirect — the test knows exactly what synthetic version the Makefile installed. modified: Makefile modified: regress/expected/age_upgrade.out modified: regress/sql/age_upgrade.sql Co-authored-by: Claude <noreply@anthropic.com>
1 parent 945a259 commit 1847644

3 files changed

Lines changed: 8 additions & 14 deletions

File tree

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ age_sql = age--1.7.0.sql
2727
# 1. Builds the install SQL from the INITIAL version-bump commit (the "from"
2828
# version). This is the age--<CURR>.sql used by CREATE EXTENSION age.
2929
# 2. Builds the install SQL from current HEAD as a synthetic "next" version
30-
# (the "to" version). This is age--<NEXT>.sql where NEXT = CURR.minor+1.
30+
# (the "to" version). This is age--<NEXT>.sql where NEXT = CURR_upgrade_test.
3131
# 3. Stamps the upgrade template with the synthetic version, producing the
3232
# upgrade script age--<CURR>--<NEXT>.sql.
3333
# 4. Temporarily installs both synthetic files into the PG extension directory
@@ -53,8 +53,8 @@ age_sql = age--1.7.0.sql
5353
AGE_CURR_VER := $(shell awk -F"'" '/default_version/ {print $$2}' age.control 2>/dev/null)
5454
# Git commit that last changed age.control — the "initial release" commit
5555
AGE_VER_COMMIT := $(shell git log -1 --format=%H -- age.control 2>/dev/null)
56-
# Synthetic next version: current minor + 1 (e.g., 1.7.0 -> 1.8.0)
57-
AGE_NEXT_VER := $(shell echo $(AGE_CURR_VER) | awk -F. '{printf "%s.%s.%s", $$1, $$2+1, $$3}')
56+
# Synthetic next version: current version with _upgrade_test suffix (e.g., 1.7.0 -> 1.7.0_upgrade_test)
57+
AGE_NEXT_VER := $(AGE_CURR_VER)_upgrade_test
5858
# The upgrade template file (e.g., age--1.7.0--y.y.y.sql); empty if not present
5959
AGE_UPGRADE_TEMPLATE := $(wildcard age--$(AGE_CURR_VER)--y.y.y.sql)
6060

@@ -296,7 +296,7 @@ ifneq ($(AGE_HAS_UPGRADE_TEST),)
296296
_install_upgrade_test_files: $(age_next_sql) $(age_upgrade_test_sql) ## Build, install synthetic files, generate cleanup script
297297
@echo "Installing upgrade test files to $(SHAREDIR)/extension/"
298298
@$(INSTALL_DATA) $(age_next_sql) $(age_upgrade_test_sql) '$(SHAREDIR)/extension/'
299-
@printf '#!/bin/sh\nrm -f "$(SHAREDIR)/extension/$(age_next_sql)" "$(SHAREDIR)/extension/$(age_upgrade_test_sql)"\n' > $(ag_regress_dir)/age_upgrade_cleanup.sh
299+
@printf '#!/bin/sh\nrm -f "$(SHAREDIR)/extension/$(age_next_sql)" "$(SHAREDIR)/extension/$(age_upgrade_test_sql)"\nrm -f "$(age_next_sql)" "$(age_upgrade_test_sql)" "$(ag_regress_dir)/age_upgrade_cleanup.sh"\n' > $(ag_regress_dir)/age_upgrade_cleanup.sh
300300
@chmod +x $(ag_regress_dir)/age_upgrade_cleanup.sh
301301

302302
installcheck: _install_upgrade_test_files

regress/expected/age_upgrade.out

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -254,12 +254,9 @@ DECLARE next_ver text;
254254
BEGIN
255255
SELECT version INTO next_ver
256256
FROM pg_available_extension_versions
257-
WHERE name = 'age' AND version <> (
258-
SELECT default_version FROM pg_available_extensions WHERE name = 'age'
259-
)
260-
ORDER BY string_to_array(version, '.')::int[] DESC
257+
WHERE name = 'age' AND version LIKE '%_upgrade_test'
258+
ORDER BY version DESC
261259
LIMIT 1;
262-
263260
IF next_ver IS NULL THEN
264261
RAISE EXCEPTION 'No next version available for upgrade test';
265262
END IF;

regress/sql/age_upgrade.sql

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,12 +200,9 @@ DECLARE next_ver text;
200200
BEGIN
201201
SELECT version INTO next_ver
202202
FROM pg_available_extension_versions
203-
WHERE name = 'age' AND version <> (
204-
SELECT default_version FROM pg_available_extensions WHERE name = 'age'
205-
)
206-
ORDER BY string_to_array(version, '.')::int[] DESC
203+
WHERE name = 'age' AND version LIKE '%_upgrade_test'
204+
ORDER BY version DESC
207205
LIMIT 1;
208-
209206
IF next_ver IS NULL THEN
210207
RAISE EXCEPTION 'No next version available for upgrade test';
211208
END IF;

0 commit comments

Comments
 (0)