From 7cef8a6eb709bb221d7165b20c794b807a46b4bd Mon Sep 17 00:00:00 2001 From: jnasbyupgrade Date: Wed, 4 Nov 2026 12:43:27 -0600 Subject: [PATCH 1/2] Require cat_tools 0.3.0 or later, with a clear error otherwise The code calls cat_tools.routine__parse_arg_types_text(), which only exists from cat_tools 0.3.0, so an older cat_tools failed obscurely at use time. Check the installed version up front in the install and 0.1.0 update scripts, and declare the floor in META.in.json. --- META.in.json | 2 +- META.json | 2 +- README.md | 2 +- sql/object_reference--0.1.0--stable.sql | 19 +++++++++++++++++++ sql/object_reference.sql | 19 +++++++++++++++++++ test/build/expected/build.out | 10 +++++----- 6 files changed, 46 insertions(+), 8 deletions(-) diff --git a/META.in.json b/META.in.json index 129a40d..44bf337 100644 --- a/META.in.json +++ b/META.in.json @@ -81,7 +81,7 @@ }, "runtime": { "requires": { - "cat_tools": 0, + "cat_tools": "0.3.0", "plpgsql": 0 } }, diff --git a/META.json b/META.json index cfaaca4..6f8b881 100644 --- a/META.json +++ b/META.json @@ -79,7 +79,7 @@ }, "runtime": { "requires": { - "cat_tools": 0, + "cat_tools": "0.3.0", "plpgsql": 0 } }, diff --git a/README.md b/README.md index ae69147..cc8e7ad 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Good documentation should be like good code comments - explain things concisely # Installation -This extension depends on the `cat_tools` extension. +This extension requires the `cat_tools` extension, version 0.3.0 or later. ```sql CREATE EXTENSION object_reference CASCADE; diff --git a/sql/object_reference--0.1.0--stable.sql b/sql/object_reference--0.1.0--stable.sql index d17a275..b5ad295 100644 --- a/sql/object_reference--0.1.0--stable.sql +++ b/sql/object_reference--0.1.0--stable.sql @@ -1,3 +1,22 @@ +/* + * Requires cat_tools 0.3.0+ (a control file's `requires` can't carry a + * version). A non-numeric version such as 'stable' is a development build and + * is let through. + */ +DO $$ +DECLARE + c_version CONSTANT text := (SELECT extversion FROM pg_catalog.pg_extension WHERE extname = 'cat_tools'); +BEGIN + IF c_version ~ '^[0-9]+(\.[0-9]+)*$' AND string_to_array(c_version, '.')::int[] < '{0,3,0}' THEN + RAISE 'object_reference requires cat_tools 0.3.0 or later' + USING ERRCODE = 'object_not_in_prerequisite_state' + , DETAIL = format('installed cat_tools version is %s', c_version) + , HINT = 'Run ALTER EXTENSION cat_tools UPDATE first.' + ; + END IF; +END +$$; + /* * Disables all three event triggers for this script (a hand-written copy of * event_trigger__disable(), which 0.1.0 lacks); event_trigger__enable() at the diff --git a/sql/object_reference.sql b/sql/object_reference.sql index 3131a55..682de0b 100644 --- a/sql/object_reference.sql +++ b/sql/object_reference.sql @@ -20,6 +20,25 @@ END $$; */ +/* + * Requires cat_tools 0.3.0+ (a control file's `requires` can't carry a + * version). A non-numeric version such as 'stable' is a development build and + * is let through. + */ +DO $$ +DECLARE + c_version CONSTANT text := (SELECT extversion FROM pg_catalog.pg_extension WHERE extname = 'cat_tools'); +BEGIN + IF c_version ~ '^[0-9]+(\.[0-9]+)*$' AND string_to_array(c_version, '.')::int[] < '{0,3,0}' THEN + RAISE 'object_reference requires cat_tools 0.3.0 or later' + USING ERRCODE = 'object_not_in_prerequisite_state' + , DETAIL = format('installed cat_tools version is %s', c_version) + , HINT = 'Run ALTER EXTENSION cat_tools UPDATE first.' + ; + END IF; +END +$$; + DO $$ BEGIN CREATE ROLE object_reference__usage NOLOGIN; diff --git a/test/build/expected/build.out b/test/build/expected/build.out index 553450f..89b5732 100644 --- a/test/build/expected/build.out +++ b/test/build/expected/build.out @@ -3,16 +3,16 @@ This extension must be loaded via CREATE EXTENSION object_reference; You really, REALLY do NOT want to try and load this via psql!!! -psql:test/temp_load.not_sql:212: WARNING: I promise you will be sorry if you try to use this as anything other than an extension! +psql:test/temp_load.not_sql:231: WARNING: I promise you will be sorry if you try to use this as anything other than an extension! -psql:test/temp_load.not_sql:213: WARNING: I promise you will be sorry if you try to use this as anything other than an extension! +psql:test/temp_load.not_sql:232: WARNING: I promise you will be sorry if you try to use this as anything other than an extension! -psql:test/temp_load.not_sql:461: WARNING: I promise you will be sorry if you try to use this as anything other than an extension! +psql:test/temp_load.not_sql:480: WARNING: I promise you will be sorry if you try to use this as anything other than an extension! @@ -22,9 +22,9 @@ psql:test/temp_load.not_sql:461: WARNING: I promise you will be sorry if you tr -psql:test/temp_load.not_sql:573: WARNING: I promise you will be sorry if you try to use this as anything other than an extension! +psql:test/temp_load.not_sql:592: WARNING: I promise you will be sorry if you try to use this as anything other than an extension! -psql:test/temp_load.not_sql:580: WARNING: I promise you will be sorry if you try to use this as anything other than an extension! +psql:test/temp_load.not_sql:599: WARNING: I promise you will be sorry if you try to use this as anything other than an extension! From 2094658b52133d1bcc790e485db167aac9508161 Mon Sep 17 00:00:00 2001 From: jnasbyupgrade Date: Wed, 4 Nov 2026 12:47:40 -0600 Subject: [PATCH 2/2] Compare only major.minor of the installed cat_tools version --- sql/object_reference--0.1.0--stable.sql | 9 +++++---- sql/object_reference.sql | 9 +++++---- test/build/expected/build.out | 10 +++++----- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/sql/object_reference--0.1.0--stable.sql b/sql/object_reference--0.1.0--stable.sql index b5ad295..562a0b4 100644 --- a/sql/object_reference--0.1.0--stable.sql +++ b/sql/object_reference--0.1.0--stable.sql @@ -1,13 +1,14 @@ /* - * Requires cat_tools 0.3.0+ (a control file's `requires` can't carry a - * version). A non-numeric version such as 'stable' is a development build and - * is let through. + * Requires cat_tools 0.3+ (a control file's `requires` can't carry a + * version). Only major.minor is compared; a version without a numeric + * major.minor, such as 'stable', is a development build and is let through. */ DO $$ DECLARE c_version CONSTANT text := (SELECT extversion FROM pg_catalog.pg_extension WHERE extname = 'cat_tools'); + c_major_minor CONSTANT text := substring(c_version FROM '^[0-9]+\.[0-9]+'); BEGIN - IF c_version ~ '^[0-9]+(\.[0-9]+)*$' AND string_to_array(c_version, '.')::int[] < '{0,3,0}' THEN + IF c_major_minor IS NOT NULL AND string_to_array(c_major_minor, '.')::int[] < '{0,3}' THEN RAISE 'object_reference requires cat_tools 0.3.0 or later' USING ERRCODE = 'object_not_in_prerequisite_state' , DETAIL = format('installed cat_tools version is %s', c_version) diff --git a/sql/object_reference.sql b/sql/object_reference.sql index 682de0b..d0b6621 100644 --- a/sql/object_reference.sql +++ b/sql/object_reference.sql @@ -21,15 +21,16 @@ $$; */ /* - * Requires cat_tools 0.3.0+ (a control file's `requires` can't carry a - * version). A non-numeric version such as 'stable' is a development build and - * is let through. + * Requires cat_tools 0.3+ (a control file's `requires` can't carry a + * version). Only major.minor is compared; a version without a numeric + * major.minor, such as 'stable', is a development build and is let through. */ DO $$ DECLARE c_version CONSTANT text := (SELECT extversion FROM pg_catalog.pg_extension WHERE extname = 'cat_tools'); + c_major_minor CONSTANT text := substring(c_version FROM '^[0-9]+\.[0-9]+'); BEGIN - IF c_version ~ '^[0-9]+(\.[0-9]+)*$' AND string_to_array(c_version, '.')::int[] < '{0,3,0}' THEN + IF c_major_minor IS NOT NULL AND string_to_array(c_major_minor, '.')::int[] < '{0,3}' THEN RAISE 'object_reference requires cat_tools 0.3.0 or later' USING ERRCODE = 'object_not_in_prerequisite_state' , DETAIL = format('installed cat_tools version is %s', c_version) diff --git a/test/build/expected/build.out b/test/build/expected/build.out index 89b5732..4b64e95 100644 --- a/test/build/expected/build.out +++ b/test/build/expected/build.out @@ -3,16 +3,16 @@ This extension must be loaded via CREATE EXTENSION object_reference; You really, REALLY do NOT want to try and load this via psql!!! -psql:test/temp_load.not_sql:231: WARNING: I promise you will be sorry if you try to use this as anything other than an extension! - psql:test/temp_load.not_sql:232: WARNING: I promise you will be sorry if you try to use this as anything other than an extension! +psql:test/temp_load.not_sql:233: WARNING: I promise you will be sorry if you try to use this as anything other than an extension! + -psql:test/temp_load.not_sql:480: WARNING: I promise you will be sorry if you try to use this as anything other than an extension! +psql:test/temp_load.not_sql:481: WARNING: I promise you will be sorry if you try to use this as anything other than an extension! @@ -22,9 +22,9 @@ psql:test/temp_load.not_sql:480: WARNING: I promise you will be sorry if you tr -psql:test/temp_load.not_sql:592: WARNING: I promise you will be sorry if you try to use this as anything other than an extension! +psql:test/temp_load.not_sql:593: WARNING: I promise you will be sorry if you try to use this as anything other than an extension! -psql:test/temp_load.not_sql:599: WARNING: I promise you will be sorry if you try to use this as anything other than an extension! +psql:test/temp_load.not_sql:600: WARNING: I promise you will be sorry if you try to use this as anything other than an extension!