From c21646cc0f677d7f9698fadf75cfb2f5272845c7 Mon Sep 17 00:00:00 2001 From: "David E. Wheeler" Date: Mon, 29 Jan 2024 15:15:43 -0500 Subject: [PATCH] Use domain-qualified name for extension An experiment to see whether the current PostgreSQL extension installation and configuration can be abused to avoid namespace collision between extensions with the same names. This shows that for relocatable extensions, at least, it can be done, but it's pretty ugly: Everything has to refer to the full extension name --- here `github.com+theory+pg-semver` --- including file names: * Control file * SQL files * The `MODULERDIR` file in `Makefile` to install files into a directory with the long extension name * The `directory` entry in the control file to match `MODULERDIR` This change doesn't actually rename all of the `sql/*.sql` files, but updates the Makefile to generate the `sql/github.com+theory+pg-semver--$VERSION.sql` file Also had to update the SQL file to use `MODULE_PATHNAME` instead of `semver` so that it can be dynamically set, and change the tests to use `CREATE EXTENSION` to create the extension to test, rather than load the file directly. The latter was required for PostgreSQL 9.0 and earlier, which are no longer supported anyway. It's possible a lot of this could be automated in the `Makefile`: replace a short name with a longer name, move and rename files, etc., but it'd be kind of a pain. The alternative is to rename everything appropriately in the repository, but that'd be ugly. Besides, changing the extension name like this means that older versions would never be properly upgraded. It'd be nicer if PostgreSQL itself were updated to support some sort of schema packaging, where everything could go into one directory named for the repository. That's probably the smarter long-term goal. --- .gitignore | 2 +- META.json | 4 +- Makefile | 5 ++- README.md | 6 +++ github.com+theory+pg-semver.control | 6 +++ semver.control | 7 --- sql/semver.sql | 44 +++++++++---------- ...semver.c => github.com+theory+pg-semver.c} | 0 test/sql/base.sql | 2 +- test/sql/corpus.sql | 2 +- 10 files changed, 42 insertions(+), 36 deletions(-) create mode 100644 github.com+theory+pg-semver.control delete mode 100644 semver.control rename src/{semver.c => github.com+theory+pg-semver.c} (100%) diff --git a/.gitignore b/.gitignore index 9853a12..645521d 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,7 @@ tmp/ *.o regression.diffs regression.out -/sql/semver--?.??.?.sql +/sql/github.com+theory+pg-semver--?.??.?.sql /semver-* /latest-changes.md /src/*.bc diff --git a/META.json b/META.json index 103e79f..de2eaf4 100644 --- a/META.json +++ b/META.json @@ -1,5 +1,5 @@ { - "name": "semver", + "name": "github.com+theory+pg-semver", "abstract": "A semantic version data type", "description": "A Postgres data type for the Semantic Version format with support for btree and hash indexing.", "version": "0.32.1", @@ -11,7 +11,7 @@ ], "license": "postgresql", "provides": { - "semver": { + "github.com+theory+pg-semver": { "abstract": "A semantic version data type", "file": "sql/semver.sql", "docfile": "doc/semver.mmd", diff --git a/Makefile b/Makefile index e70adb7..3d75680 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,4 @@ +NAME = semver EXTENSION = $(shell grep -m 1 '"name":' META.json | \ sed -e 's/[[:space:]]*"name":[[:space:]]*"\([^"]*\)",/\1/') EXTVERSION = $(shell grep -m 1 '[[:space:]]\{8\}"version":' META.json | \ @@ -5,7 +6,7 @@ EXTVERSION = $(shell grep -m 1 '[[:space:]]\{8\}"version":' META.json | \ DISTVERSION = $(shell grep -m 1 '[[:space:]]\{3\}"version":' META.json | \ sed -e 's/[[:space:]]*"version":[[:space:]]*"\([^"]*\)",\{0,1\}/\1/') -MODULEDIR = semver +MODULEDIR = $(EXTENSION) DATA = $(wildcard sql/*.sql) DOCS = $(wildcard doc/*.mmd) TESTS = $(wildcard test/sql/*.sql) @@ -25,7 +26,7 @@ include $(PGXS) all: sql/$(EXTENSION)--$(EXTVERSION).sql -sql/$(EXTENSION)--$(EXTVERSION).sql: sql/$(EXTENSION).sql +sql/$(EXTENSION)--$(EXTVERSION).sql: sql/$(NAME).sql cp $< $@ .PHONY: results diff --git a/README.md b/README.md index 4bd4312..0e78621 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,12 @@ semver 0.32.0 ============= +Namespace Experiment +-------------------- + +Experimental branch to try naming an extension with a source code repository URL +similar to Go packages. + [![PGXN version](https://badge.fury.io/pg/semver.svg)](https://badge.fury.io/pg/semver) [![Build Status](https://github.com/theory/pg-semver/workflows/CI/badge.svg)](https://github.com/theory/pg-semver/actions) diff --git a/github.com+theory+pg-semver.control b/github.com+theory+pg-semver.control new file mode 100644 index 0000000..3625250 --- /dev/null +++ b/github.com+theory+pg-semver.control @@ -0,0 +1,6 @@ +# github.com+theory+pg-semver extension +comment = 'Semantic version data type' +default_version = '0.32.1' +directory = 'github.com+theory+pg-semver' +module_pathname = '$libdir/github.com+theory+pg-semver' +relocatable = true diff --git a/semver.control b/semver.control deleted file mode 100644 index fbc6d1f..0000000 --- a/semver.control +++ /dev/null @@ -1,7 +0,0 @@ -# semver extension -comment = 'Semantic version data type' -default_version = '0.32.1' - -directory = 'semver' -module_pathname = '$libdir/semver' -relocatable = true diff --git a/sql/semver.sql b/sql/semver.sql index cd23b47..11b3de6 100644 --- a/sql/semver.sql +++ b/sql/semver.sql @@ -26,22 +26,22 @@ CREATE TYPE semver; -- CREATE OR REPLACE FUNCTION semver_in(cstring) RETURNS semver - AS 'semver' + AS 'MODULE_PATHNAME' LANGUAGE C STRICT IMMUTABLE; CREATE OR REPLACE FUNCTION semver_out(semver) RETURNS cstring - AS 'semver' + AS 'MODULE_PATHNAME' LANGUAGE C STRICT IMMUTABLE; CREATE OR REPLACE FUNCTION semver_recv(internal) RETURNS semver - AS 'semver' + AS 'MODULE_PATHNAME' LANGUAGE C STRICT IMMUTABLE; CREATE OR REPLACE FUNCTION semver_send(semver) RETURNS bytea - AS 'semver' + AS 'MODULE_PATHNAME' LANGUAGE C STRICT IMMUTABLE; -- @@ -67,7 +67,7 @@ CREATE TYPE semver ( CREATE OR REPLACE FUNCTION to_semver(text) RETURNS semver - AS 'semver' + AS 'MODULE_PATHNAME' LANGUAGE C STRICT IMMUTABLE; -- @@ -76,12 +76,12 @@ CREATE OR REPLACE FUNCTION to_semver(text) CREATE OR REPLACE FUNCTION semver(text) RETURNS semver - AS 'semver', 'text_to_semver' + AS 'MODULE_PATHNAME', 'text_to_semver' LANGUAGE C STRICT IMMUTABLE; CREATE OR REPLACE FUNCTION text(semver) RETURNS text - AS 'semver', 'semver_to_text' + AS 'MODULE_PATHNAME', 'semver_to_text' LANGUAGE C STRICT IMMUTABLE; CREATE OR REPLACE FUNCTION semver(numeric) @@ -127,7 +127,7 @@ CREATE CAST (bigint AS semver) WITH FUNCTION semver(bigint); CREATE OR REPLACE FUNCTION semver_eq(semver, semver) RETURNS bool - AS 'semver' + AS 'MODULE_PATHNAME' LANGUAGE C STRICT IMMUTABLE; CREATE OPERATOR = ( @@ -143,7 +143,7 @@ CREATE OPERATOR = ( CREATE OR REPLACE FUNCTION semver_ne(semver, semver) RETURNS bool - AS 'semver' + AS 'MODULE_PATHNAME' LANGUAGE C STRICT IMMUTABLE; CREATE OPERATOR <> ( @@ -157,7 +157,7 @@ CREATE OPERATOR <> ( CREATE OR REPLACE FUNCTION semver_le(semver, semver) RETURNS bool - AS 'semver' + AS 'MODULE_PATHNAME' LANGUAGE C STRICT IMMUTABLE; CREATE OPERATOR <= ( @@ -169,7 +169,7 @@ CREATE OPERATOR <= ( CREATE OR REPLACE FUNCTION semver_lt(semver, semver) RETURNS bool - AS 'semver' + AS 'MODULE_PATHNAME' LANGUAGE C STRICT IMMUTABLE; CREATE OPERATOR < ( @@ -181,7 +181,7 @@ CREATE OPERATOR < ( CREATE OR REPLACE FUNCTION semver_ge(semver, semver) RETURNS bool - AS 'semver' + AS 'MODULE_PATHNAME' LANGUAGE C STRICT IMMUTABLE; CREATE OPERATOR >= ( @@ -193,7 +193,7 @@ CREATE OPERATOR >= ( CREATE OR REPLACE FUNCTION semver_gt(semver, semver) RETURNS bool - AS 'semver' + AS 'MODULE_PATHNAME' LANGUAGE C STRICT IMMUTABLE; CREATE OPERATOR > ( @@ -209,12 +209,12 @@ CREATE OPERATOR > ( CREATE OR REPLACE FUNCTION semver_cmp(semver, semver) RETURNS int4 - AS 'semver' + AS 'MODULE_PATHNAME' LANGUAGE C STRICT IMMUTABLE; CREATE OR REPLACE FUNCTION hash_semver(semver) RETURNS int4 - AS 'semver' + AS 'MODULE_PATHNAME' LANGUAGE C STRICT IMMUTABLE; -- @@ -245,7 +245,7 @@ DEFAULT FOR TYPE semver USING hash AS CREATE OR REPLACE FUNCTION semver_smaller(semver, semver) RETURNS semver - AS 'semver' + AS 'MODULE_PATHNAME' LANGUAGE C STRICT IMMUTABLE; CREATE AGGREGATE min(semver) ( @@ -256,7 +256,7 @@ CREATE AGGREGATE min(semver) ( CREATE OR REPLACE FUNCTION semver_larger(semver, semver) RETURNS semver - AS 'semver' + AS 'MODULE_PATHNAME' LANGUAGE C STRICT IMMUTABLE; CREATE AGGREGATE max(semver) ( @@ -271,7 +271,7 @@ CREATE AGGREGATE max(semver) ( CREATE OR REPLACE FUNCTION is_semver(text) RETURNS bool - AS 'semver' + AS 'MODULE_PATHNAME' LANGUAGE C STRICT IMMUTABLE; -- @@ -280,22 +280,22 @@ CREATE OR REPLACE FUNCTION is_semver(text) CREATE OR REPLACE FUNCTION get_semver_major(semver) RETURNS int4 - AS 'semver' + AS 'MODULE_PATHNAME' LANGUAGE C STRICT IMMUTABLE; CREATE OR REPLACE FUNCTION get_semver_minor(semver) RETURNS int4 - AS 'semver' + AS 'MODULE_PATHNAME' LANGUAGE C STRICT IMMUTABLE; CREATE OR REPLACE FUNCTION get_semver_patch(semver) RETURNS int4 - AS 'semver' + AS 'MODULE_PATHNAME' LANGUAGE C STRICT IMMUTABLE; CREATE OR REPLACE FUNCTION get_semver_prerelease(semver) RETURNS text - AS 'semver' + AS 'MODULE_PATHNAME' LANGUAGE C STRICT IMMUTABLE; CREATE TYPE semverrange AS RANGE (SUBTYPE = semver); diff --git a/src/semver.c b/src/github.com+theory+pg-semver.c similarity index 100% rename from src/semver.c rename to src/github.com+theory+pg-semver.c diff --git a/test/sql/base.sql b/test/sql/base.sql index af599d8..e471e74 100644 --- a/test/sql/base.sql +++ b/test/sql/base.sql @@ -2,7 +2,7 @@ BEGIN; \i test/pgtap-core.sql -\i sql/semver.sql +CREATE EXTENSION "github.com+theory+pg-semver"; SELECT plan(334); --SELECT * FROM no_plan(); diff --git a/test/sql/corpus.sql b/test/sql/corpus.sql index 1f5f637..cdc8881 100644 --- a/test/sql/corpus.sql +++ b/test/sql/corpus.sql @@ -4,7 +4,7 @@ BEGIN; -- Test the SemVer corpus from https://regex101.com/r/Ly7O1x/3/. \i test/pgtap-core.sql -\i sql/semver.sql +CREATE EXTENSION "github.com+theory+pg-semver"; SELECT plan(71); --SELECT * FROM no_plan();