From 24134fdad54a6b3c08e0347bf88718159497e496 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: * The Control file * SQL files * The `MODULERDIR` variable in the `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 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 | 3 ++- README.md | 6 ++++++ github.com+theory+pg-semver.control | 6 ++++++ semver.control | 7 ------- src/{semver.c => github.com+theory+pg-semver.c} | 0 test/sql/base.sql | 2 +- test/sql/corpus.sql | 2 +- 9 files changed, 19 insertions(+), 13 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 d7adc64..ee88f7a 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 8777ed1..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 | \ @@ -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 d8956e2..a02c06c 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/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 53adb30..e471e74 100644 --- a/test/sql/base.sql +++ b/test/sql/base.sql @@ -2,7 +2,7 @@ BEGIN; \i test/pgtap-core.sql -CREATE EXTENSION semver; +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 b3fdd8b..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 -CREATE EXTENSION semver; +CREATE EXTENSION "github.com+theory+pg-semver"; SELECT plan(71); --SELECT * FROM no_plan();