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..562a0b4 100644 --- a/sql/object_reference--0.1.0--stable.sql +++ b/sql/object_reference--0.1.0--stable.sql @@ -1,3 +1,23 @@ +/* + * 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_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) + , 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..d0b6621 100644 --- a/sql/object_reference.sql +++ b/sql/object_reference.sql @@ -20,6 +20,26 @@ END $$; */ +/* + * 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_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) + , 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..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: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: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: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: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: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: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: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: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: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:600: WARNING: I promise you will be sorry if you try to use this as anything other than an extension!