Skip to content

Commit

Permalink
Use domain-qualified name for extension
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
theory committed Jan 29, 2024
1 parent 9ed9489 commit 24134fd
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions META.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -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 | \
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
6 changes: 6 additions & 0 deletions github.com+theory+pg-semver.control
Original file line number Diff line number Diff line change
@@ -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
7 changes: 0 additions & 7 deletions semver.control

This file was deleted.

File renamed without changes.
2 changes: 1 addition & 1 deletion test/sql/base.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion test/sql/corpus.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 24134fd

Please sign in to comment.