Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions META.in.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "test_factory",
"abstract": "Framework for managing test data",
"description": "Provides functions for registering commands to create test data and obtaining data during testing",
"version": "0.5.0",
"version": "1.0.0",
"maintainer": "Jim Nasby <Jim.Nasby@BlueTreble.com>",
"license": {"BSD 2 Clause": "http://opensource.org/licenses/bsd-license.php"},

Expand All @@ -12,31 +12,31 @@
"abstract": "Framework for managing test data",
"file": "sql/test_factory.sql",
"docfile": "doc/test_factory.asc",
"version": "0.5.0"
"version": "1.0.0"
},
"test_factory_pgtap": {
"abstract": "pgTap extension for test_factory",
"file": "sql/test_factory_pgtap.sql",
"docfile": "doc/test_factory.asc",
"version": "0.1.0"
"version": "1.0.0"
}
},


"release_status": "stable",

"generated_by": "Jim Nasby <Jim.Nasby@BlueTreble.com>",
"generated_by": "Jim Nasby <Jim.Nasby@gmail.com>",

"tags": [ "testing", "unit test", "tests", "test data", "test factory" ],

"resources": {
"homepage": "http://github.com/BlueTreble/test_factory/",
"homepage": "http://github.com/Postgres-Extensions/test_factory/",
"bugtracker": {
"web": "http://github.com/BlueTreble/test_factory/issues"
"web": "http://github.com/Postgres-Extensions/test_factory/issues"
},
"repository": {
"url": "git://github.com/BlueTreble/test_factory.git",
"web": "http://github.com/BlueTreble/test_factory/",
"url": "git://github.com/Postgres-Extensions/test_factory.git",
"web": "http://github.com/Postgres-Extensions/test_factory/",
"type": "git"
}
},
Expand Down
16 changes: 8 additions & 8 deletions META.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"name": "test_factory",
"abstract": "Framework for managing test data",
"description": "Provides functions for registering commands to create test data and obtaining data during testing",
"version": "0.5.0",
"version": "1.0.0",
"maintainer": "Jim Nasby <Jim.Nasby@BlueTreble.com>",
"license": {"BSD 2 Clause": "http://opensource.org/licenses/bsd-license.php"},

Expand All @@ -15,31 +15,31 @@
"abstract": "Framework for managing test data",
"file": "sql/test_factory.sql",
"docfile": "doc/test_factory.asc",
"version": "0.5.0"
"version": "1.0.0"
},
"test_factory_pgtap": {
"abstract": "pgTap extension for test_factory",
"file": "sql/test_factory_pgtap.sql",
"docfile": "doc/test_factory.asc",
"version": "0.1.0"
"version": "1.0.0"
}
},


"release_status": "stable",

"generated_by": "Jim Nasby <Jim.Nasby@BlueTreble.com>",
"generated_by": "Jim Nasby <Jim.Nasby@gmail.com>",

"tags": [ "testing", "unit test", "tests", "test data", "test factory" ],

"resources": {
"homepage": "http://github.com/BlueTreble/test_factory/",
"homepage": "http://github.com/Postgres-Extensions/test_factory/",
"bugtracker": {
"web": "http://github.com/BlueTreble/test_factory/issues"
"web": "http://github.com/Postgres-Extensions/test_factory/issues"
},
"repository": {
"url": "git://github.com/BlueTreble/test_factory.git",
"web": "http://github.com/BlueTreble/test_factory/",
"url": "git://github.com/Postgres-Extensions/test_factory.git",
"web": "http://github.com/Postgres-Extensions/test_factory/",
"type": "git"
}
},
Expand Down
35 changes: 32 additions & 3 deletions pgxntool/HISTORY.asc
Original file line number Diff line number Diff line change
@@ -1,10 +1,37 @@
1.1.1
-----
== Fix pg_tle exception handler and empty upgrade files
The exception handler for `uninstall_extension()` now correctly catches
`no_data_found` (P0002) instead of `undefined_object` (42704). Empty upgrade
files are now treated as valid no-op upgrades for version bumps. Added
`ON_ERROR_STOP=1` to `run_pgtle_sql()` so psql errors propagate correctly.

1.1.0
-----
== Use unique database names for tests
Tests now use a unique database name based on the project name and a hash of the
current directory. This prevents test conflicts when running tests for multiple
projects in parallel.

== Add 3-way merge support for setup files after pgxntool-sync
New `update-setup-files.sh` script handles merging changes to files initially
copied by `setup.sh` (`.gitignore`, `test/deps.sql`). After running `make
pgxntool-sync`, the script performs a 3-way merge if both you and pgxntool have
modified the same file, using git's native conflict markers for resolution.


1.0.0
-----
== Fix broken multi-extension support
Prior to this fix, distributions with multiple extensions or extensions with versions different from the PGXN distribution version were completely broken. Extension versions are now correctly read from each `.control` file's `default_version` instead of using META.json's distribution version.
Prior to this fix, distributions with multiple extensions or extensions with
versions different from the PGXN distribution version were completely broken.
Extension versions are now correctly read from each `.control` file's
`default_version` instead of using META.json's distribution version.

== Add pg_tle support
New `make pgtle` target generates pg_tle registration SQL for extensions. Supports pg_tle version ranges (1.0.0-1.4.0, 1.4.0-1.5.0, 1.5.0+) with appropriate API calls for each range. See README for usage.
New `make pgtle` target generates pg_tle registration SQL for extensions.
Supports pg_tle version ranges (1.0.0-1.4.0, 1.4.0-1.5.0, 1.5.0+) with
appropriate API calls for each range. See README for usage.

== Use git tags for distribution versioning
The `tag` and `rmtag` targets now create/delete git tags instead of branches.
Expand All @@ -16,7 +43,9 @@ The `--load-language` option was removed from `pg_regress` in 13.
As part of this change, you will want to review the changes to test/deps.sql.

=== Support asciidoc documentation targets
By default, if asciidoctor or asciidoc exists on the system, any files in doc/ that end in .adoc or .asciidoc will be processed to html.
By default, if asciidoctor or asciidoc exists on the system, any files in doc/
that end in .adoc or .asciidoc will be processed to html.

See the README for full details.

=== Support 9.2
Expand Down
19 changes: 17 additions & 2 deletions pgxntool/base.mk
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ TEST__SOURCE__SQL_FILES = $(patsubst $(TESTDIR)/input/%.source,$(TESTDIR)/sql/%
TEST__SOURCE__EXPECTED_FILES = $(patsubst $(TESTDIR)/output/%.source,$(TESTDIR)/expected/%.out,$(TEST__SOURCE__OUTPUT_FILES))
REGRESS = $(sort $(notdir $(subst .source,,$(TEST_FILES:.sql=)))) # Sort is to get unique list
REGRESS_OPTS = --inputdir=$(TESTDIR) --outputdir=$(TESTOUT) # See additional setup below

# Generate unique database name for tests to prevent conflicts across projects
# Uses project name + first 5 chars of md5 hash of current directory
# This prevents multiple test runs in different directories from clobbering each other
REGRESS_DBHASH := $(shell echo $(CURDIR) | (md5 2>/dev/null || md5sum) | cut -c1-5)
REGRESS_DBNAME := $(or $(PGXN),regression)_$(REGRESS_DBHASH)
REGRESS_OPTS += --dbname=$(REGRESS_DBNAME)
MODULES = $(patsubst %.c,%,$(wildcard src/*.c))
ifeq ($(strip $(MODULES)),)
MODULES =# Set to NUL so PGXS doesn't puke
Expand Down Expand Up @@ -291,17 +298,25 @@ print-% : ; $(info $* is $(flavor $*) variable set to "$($*)") @true
#
# This is setup to allow any number of pull targets by defining special
# variables. pgxntool-sync-release is an example of this.
.PHONY: pgxn-sync-%
#
# After the subtree pull, we run update-setup-files.sh to handle files that
# were initially copied by setup.sh (like .gitignore). This script does a
# 3-way merge if both you and pgxntool changed the file.
.PHONY: pgxntool-sync-%
pgxntool-sync-%:
git subtree pull -P pgxntool --squash -m "Pull pgxntool from $($@)" $($@)
@old_commit=$$(git log -1 --format=%H -- pgxntool/) && \
git subtree pull -P pgxntool --squash -m "Pull pgxntool from $($@)" $($@) && \
pgxntool/update-setup-files.sh "$$old_commit"
pgxntool-sync: pgxntool-sync-release

# DANGER! Use these with caution. They may add extra crap to your history and
# could make resolving merges difficult!
pgxntool-sync-release := git@github.com:decibel/pgxntool.git release
pgxntool-sync-stable := git@github.com:decibel/pgxntool.git stable
pgxntool-sync-master := git@github.com:decibel/pgxntool.git master
pgxntool-sync-local := ../pgxntool release # Not the same as PGXNTOOL_DIR!
pgxntool-sync-local-stable := ../pgxntool stable # Not the same as PGXNTOOL_DIR!
pgxntool-sync-local-master := ../pgxntool master # Not the same as PGXNTOOL_DIR!

distclean:
rm -f $(PGXNTOOL_distclean)
Expand Down
17 changes: 17 additions & 0 deletions pgxntool/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@
# This file is meant to be sourced by other scripts, not executed directly.
# Usage: source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"

# =============================================================================
# SETUP FILES CONFIGURATION
# =============================================================================
# Files copied by setup.sh and tracked by update-setup-files.sh for sync updates.
# Format: "source_in_pgxntool:destination_in_project"
# =============================================================================
SETUP_FILES=(
"_.gitignore:.gitignore"
"test/deps.sql:test/deps.sql"
)

# Symlinks created by setup.sh and verified by update-setup-files.sh
# Format: "destination:target"
SETUP_SYMLINKS=(
"test/pgxntool:../pgxntool/test/pgxntool"
)

# Error function - outputs to stderr but doesn't exit
# Usage: error "message"
error() {
Expand Down
28 changes: 13 additions & 15 deletions pgxntool/pgtle.sh
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ run_pgtle_sql() {
if [ -f "$sql_file" ]; then
found=1
echo "Running $sql_file..." >&2
psql --no-psqlrc --file="$sql_file" || exit 1
psql --no-psqlrc -v ON_ERROR_STOP=1 --file="$sql_file" || exit 1
fi
done

Expand Down Expand Up @@ -545,10 +545,7 @@ discover_sql_files() {
UPGRADE_FILES=() # Reset array
debug 30 "discover_sql_files: Reset UPGRADE_FILES array"
while IFS= read -r -d '' file; do
# Error on empty upgrade files
if [ ! -s "$file" ]; then
die 1 "Empty upgrade file found: $file"
fi
# Empty upgrade files are allowed (no-op upgrades)
local basename=$(basename "$file" .sql)
local dash_count=$(echo "$basename" | grep -o -- "--" | wc -l | tr -d '[:space:]')
if [ "$dash_count" -eq 2 ]; then
Expand Down Expand Up @@ -615,6 +612,7 @@ wrap_sql_content() {
validate_delimiter "$sql_file"

# Output wrapped SQL with proper indentation
# Empty files are valid (no-op upgrades)
echo " ${PGTLE_DELIMITER}"
cat "$sql_file"
echo " ${PGTLE_DELIMITER}"
Expand Down Expand Up @@ -661,17 +659,17 @@ generate_header() {
* - Upgrade paths: ${upgrade_count} path(s)
* - Default version: ${DEFAULT_VERSION}
*
* Installation instructions:
* 1. Ensure pg_tle is installed:
* CREATE EXTENSION pg_tle;
* Installation:
* Recommended: make run-pgtle
* (or: pgxntool/pgtle.sh --run)
*
* 2. Ensure you have pgtle_admin role:
* GRANT pgtle_admin TO your_username;
* This automatically detects your pg_tle version and runs the correct file.
*
* 3. Run this file:
* psql -f $(basename "$output_file")
* Prerequisites:
* - pg_tle extension installed (CREATE EXTENSION pg_tle;)
* - pgtle_admin role (GRANT pgtle_admin TO your_username;)
*
* 4. Create the extension:
* After registration, create the extension:
* CREATE EXTENSION ${EXTENSION};
*
* Version compatibility:
Expand Down Expand Up @@ -799,8 +797,8 @@ DO \$\$
BEGIN
PERFORM pgtle.uninstall_extension('${EXTENSION}');
EXCEPTION
WHEN undefined_object THEN
-- Extension might not exist yet
WHEN no_data_found THEN
-- Extension not registered yet (pg_tle raises P0002, not 42704)
NULL;
END
\$\$;
Expand Down
41 changes: 32 additions & 9 deletions pgxntool/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,44 @@ safecp () {
fi
}

safecp pgxntool/_.gitignore .gitignore
safecp pgxntool/META.in.json META.in.json
# =============================================================================
# SETUP FILES
# =============================================================================
# SETUP_FILES and SETUP_SYMLINKS are defined in lib.sh
# These are also used by update-setup-files.sh for sync updates.
# =============================================================================

# Copy tracked setup files (defined in lib.sh)
for entry in "${SETUP_FILES[@]}"; do
src="pgxntool/${entry%%:*}"
dest="${entry##*:}"
# Create parent directory if needed
mkdir -p "$(dirname "$dest")"
safecp "$src" "$dest"
done

# Create tracked symlinks (defined in lib.sh)
for entry in "${SETUP_SYMLINKS[@]}"; do
dest="${entry%%:*}"
target="${entry##*:}"
mkdir -p "$(dirname "$dest")"
if [ ! -e "$dest" ]; then
echo "Creating symlink $dest -> $target"
ln -s "$target" "$dest"
git add "$dest"
else
echo "$dest already exists"
fi
done

# META.in.json and Makefile are NOT in SETUP_FILES because users heavily customize them
safecp pgxntool/META.in.json META.in.json
safecreate Makefile include pgxntool/base.mk

make META.json
git add META.json

mkdir -p sql test src

cd test
mkdir -p sql
safecp ../pgxntool/test/deps.sql deps.sql
[ -d pgxntool ] || ln -s ../pgxntool/test/pgxntool .
git add pgxntool
mkdir -p sql test/sql src
git status

echo "If you won't be creating C code then you can:
Expand Down
Loading