Skip to content
Merged
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
12 changes: 7 additions & 5 deletions META.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
"name": "pg_sheet_fdw",
"abstract": "foreign data wrapper for access to SheetReader",
"description": "This Foreign Data Wrapper gives Postgresql access to SheetReader, which is a fast Excel sheet reader. It enables Postgresql to access local .xlsx files (Excel Sheets) as foreign tables.",
"version": "0.1.0",
"maintainer": "Harry",
"license": "mit",
"version": "0.1.2",
"maintainer": "polydbms",
"license": [
"mit"
],
"provides": {
"pg_sheet_fdw": {
"abstract": "foreign data wrapper for access to SheetReader",
"file": "pg_sheet_fdw--0.1.sql",
"file": "pg_sheet_fdw--0.1.2.sql",
"docfile": "README.md",
"version": "0.1.0"
"version": "0.1.2"
}
},
"prereqs": {
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
EXTENSION = pg_sheet_fdw
MODULE_big = pg_sheet_fdw
DATA = pg_sheet_fdw--0.1.sql
DATA = pg_sheet_fdw--0.1.2.sql
OBJS = src/pg_sheet_fdw.o src/ParserInterface.o submodules/sheetreader/src/XlsxFile.o submodules/sheetreader/src/XlsxSheet.o submodules/sheetreader/src/miniz/miniz.o
PG_LIBS = -lpq
PG_CPPFLAGS = -I./include -I./submodules/sheetreader/src
Expand Down
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,42 @@ Creates a PGXN release bundle (zip file) for uploading to the official PGXN regi

> **Note**: Commit `.gitattributes` before running `bundle.sh` to ensure development files are properly excluded from the bundle.

## Version Management

When releasing a new version of the extension, you must update the version number in **four files** to maintain consistency:

### Files to Update

1. **`META.json`** (3 locations):
```json
{
"version": "X.Y.Z", // Line 5: Main version
"provides": {
"pg_sheet_fdw": {
"file": "pg_sheet_fdw--X.Y.Z.sql", // Line 11: SQL filename
"version": "X.Y.Z" // Line 13: Provides version
}
}
}
```

2. **`pg_sheet_fdw.control`**:
```
default_version = 'X.Y.Z'
```

3. **`Makefile`**:
```makefile
DATA = pg_sheet_fdw--X.Y.Z.sql
```

4. **SQL file**: Rename the file itself:
```bash
git mv pg_sheet_fdw--OLD.sql pg_sheet_fdw--X.Y.Z.sql
```

> **Important**: All version numbers must match exactly, including the SQL filename, or PostgreSQL installation will fail.

## Test

In the /test directory are small Excel Sheets for testing. The script "/test/test_fdw_runall.sh" executes basic functioning tests on the local PostgreSQL Server. It calls `psql --echo-errors -v ON_ERROR_STOP=on -f ` on all sql test files. The command can be modified if local user credentials are needed. Also keep in mind, that the postgres user needs reading permission on all sheets.
Expand Down
68 changes: 56 additions & 12 deletions bundle.sh
Original file line number Diff line number Diff line change
@@ -1,25 +1,69 @@
#!/bin/bash

echo "Creating PGXN bundle..."
set -e

echo "Creating PGXN bundle with submodules..."
echo "This will validate META.json and create a release zip file."
echo ""

# Run pgxn-bundle in Docker container
docker run --rm \
# Step 1: Validate META.json using pgxn-bundle
echo "Validating META.json..."
VALIDATION_OUTPUT=$(docker run --rm \
-v $(pwd):/repo \
-w /repo \
pgxn/pgxn-tools \
pgxn-bundle || true
pgxn-bundle 2>&1 || true)

if echo "$VALIDATION_OUTPUT" | grep -q "META.json is OK"; then
echo "✓ META.json is valid"
else
echo "✗ META.json validation failed"
echo "$VALIDATION_OUTPUT"
exit 1
fi
echo ""

# Check if bundle was created
if [ -f pg_sheet_fdw-*.zip ] || [ -f pg_sheet_fdw-0.1.0.zip ]; then
echo "✓ Bundle created successfully!"
echo ""
echo "The bundle zip file is ready for upload to PGXN:"
ls -lh pg_sheet_fdw-*.zip 2>/dev/null
# Step 2: Get version from META.json
VERSION=$(grep -oP '"version":\s*"\K[^"]+' META.json | head -n 1)
BUNDLE_NAME="pg_sheet_fdw-${VERSION}"
ZIP_FILE="${BUNDLE_NAME}.zip"

# Remove old bundle if it exists
rm -f "$ZIP_FILE"

echo "Creating bundle: ${ZIP_FILE}"
echo "Including submodule contents..."
echo ""

# Step 3: Create a temporary directory for the bundle
TEMP_DIR=$(mktemp -d)
trap "rm -rf $TEMP_DIR" EXIT

# Step 4: Archive the main repository
git archive --format=tar --prefix="${BUNDLE_NAME}/" HEAD | tar -x -C "$TEMP_DIR"

# Step 5: Archive each submodule and add to the bundle
git submodule foreach --quiet 'git archive --format=tar --prefix='"${BUNDLE_NAME}"'/$path/ HEAD | tar -x -C '"$TEMP_DIR"

# Step 6: Create the zip file
cd "$TEMP_DIR"
zip -r -q "$OLDPWD/$ZIP_FILE" "${BUNDLE_NAME}/"
cd "$OLDPWD"

echo "Bundle contents (first 50 entries):"
unzip -l "$ZIP_FILE" | head -n 50

echo ""
echo "Verifying submodule inclusion..."
SUBMODULE_FILES=$(unzip -l "$ZIP_FILE" | grep -c "submodules/sheetreader/src/" || echo "0")
if [ "$SUBMODULE_FILES" -gt 0 ]; then
echo "✓ Submodule files included: $SUBMODULE_FILES files"
else
echo "✗ Bundle creation failed. Check the errors above."
exit 1
echo "✗ Warning: No submodule files found in bundle"
fi

echo ""
echo "✓ Bundle created successfully!"
echo ""
echo "The bundle zip file is ready for upload to PGXN:"
ls -lh "$ZIP_FILE"
34 changes: 30 additions & 4 deletions compile_In_Docker.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/bash
# This script starts the docker container, copies over all installation files and runs the compilation and installation.
# Usage: ./compile_In_Docker.sh [pg13|pg16|pgxn|all]

run_test_env() {
local PG_VERSION=$1
Expand All @@ -10,6 +11,9 @@ run_test_env() {
if [ "$PG_VERSION" == "16" ]; then
CONTAINER_NAME="${CONTAINER_NAME}_16"
IMAGE_NAME="${IMAGE_NAME}_16"
elif [ "$PG_VERSION" == "pgxn" ]; then
CONTAINER_NAME="pg_sheet_fdw_pgxn_test"
IMAGE_NAME="pg_sheet_fdw_pgxn"
fi

echo "==========[ Processing PostgreSQL $PG_VERSION Environment ]=========="
Expand Down Expand Up @@ -51,8 +55,30 @@ run_test_env() {
echo ""
}

# Run for PG13 (Default)
run_test_env "13" "Dockerfile"
# Parse command line argument
TEST_MODE="${1:-all}"

# Run for PG16
run_test_env "16" "Dockerfile.pg16"
case "$TEST_MODE" in
pg13)
run_test_env "13" "Dockerfile"
;;
pg16)
run_test_env "16" "Dockerfile.pg16"
;;
pgxn)
run_test_env "pgxn" "Dockerfile.pgxn-test"
;;
all)
run_test_env "13" "Dockerfile"
run_test_env "16" "Dockerfile.pg16"
run_test_env "pgxn" "Dockerfile.pgxn-test"
;;
*)
echo "Usage: $0 [pg13|pg16|pgxn|all]"
echo " pg13 - Run only PostgreSQL 13 tests"
echo " pg16 - Run only PostgreSQL 16 tests"
echo " pgxn - Run only PGXN installation test"
echo " all - Run all tests (default)"
exit 1
;;
esac
73 changes: 73 additions & 0 deletions docker/Dockerfile.pgxn-test
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Dockerfile for testing pg_sheet_fdw installation from PGXN
# This verifies that the extension can be installed by end users from the official PGXN registry
FROM ubuntu:22.04

ENV DEBIAN_FRONTEND noninteractive

# Install prerequisites
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
gcc \
git \
libc-dev \
make \
cmake \
ca-certificates \
libssl-dev \
curl \
nano \
gpg \
gnupg2 \
software-properties-common \
apt-transport-https \
lsb-release \
gdb \
g++ \
python3 \
python3-pip \
&& rm -rf /var/lib/apt/lists/*

# Install PostgreSQL 16
RUN curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc| gpg --dearmor -o /etc/apt/trusted.gpg.d/postgresql.gpg
RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" | tee /etc/apt/sources.list.d/pgdg.list

RUN apt-get update && apt-get install -y --no-install-recommends \
postgresql-16 \
postgresql-server-dev-16

# Install PGXN client and sudo
RUN pip3 install pgxnclient && \
apt-get update && apt-get install -y sudo && rm -rf /var/lib/apt/lists/*

# Initialize PostgreSQL and install pg_sheet_fdw from PGXN as root
USER postgres
RUN /etc/init.d/postgresql start && \
psql --command "ALTER USER postgres WITH PASSWORD '123456';" && \
createdb -O postgres testdb

USER root
RUN /etc/init.d/postgresql start && \
sleep 3 && \
pgxn install pg_sheet_fdw && \
/etc/init.d/postgresql stop

# Copy test files to verify the installation works properly
RUN mkdir -p /pg_sheet_fdw
COPY test /pg_sheet_fdw/test

# Switch to postgres user for runtime
USER postgres





# Configure PostgreSQL for external access
RUN echo "host all all 0.0.0.0/0 md5" >> /etc/postgresql/16/main/pg_hba.conf
RUN echo "listen_addresses='*'" >> /etc/postgresql/16/main/postgresql.conf

EXPOSE 5432

VOLUME ["/etc/postgresql", "/var/log/postgresql", "/var/lib/postgresql"]

CMD ["/usr/lib/postgresql/16/bin/postgres", "-D", "/var/lib/postgresql/16/main", "-c", "config_file=/etc/postgresql/16/main/postgresql.conf"]
48 changes: 44 additions & 4 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,45 @@
# Postgres Docker Image for PG_Sheet
This Docker Image compiles and tests the Sheet Reader Foreign Data Wrapper PG_Sheet.
# Docker Images for pg_sheet_fdw

Use the Makefile for Image building.
Alternatively, the script ../compile_In_Docker.sh also builds the Image, starts a container and runs tests on it. The container keeps running afterward.
This directory contains Docker configurations for building, testing, and verifying the pg_sheet_fdw extension across different PostgreSQL versions and installation methods.

## Dockerfiles

| File | PostgreSQL | Installation Method |
|------|------------|---------------------|
| `Dockerfile` | 13 | Build from local source |
| `Dockerfile.pg16` | 16 (recommended) | Build from local source |
| `Dockerfile.pgxn-test` | 16 | Install from PGXN registry |

**Note**: `Dockerfile.pgxn-test` tests real-world end-user installation via `pgxn install pg_sheet_fdw` from https://pgxn.org/dist/pg_sheet_fdw/

## Usage

### Using compile_In_Docker.sh

From the project root:

```bash
# Run all tests (PG13, PG16, and PGXN) - default
./compile_In_Docker.sh

# Run only PostgreSQL 13 tests (uses Dockerfile)
./compile_In_Docker.sh pg13

# Run only PostgreSQL 16 tests (uses Dockerfile.pg16)
./compile_In_Docker.sh pg16

# Run only PGXN installation test (uses Dockerfile.pgxn-test)
./compile_In_Docker.sh pgxn
```


The script builds Docker images, starts containers, runs the full test suite, and keeps containers running afterward.

### Using Makefile

```bash
cd docker
make
```

This builds the default Docker images (PG13 and PG16 from local source).
File renamed without changes.
2 changes: 1 addition & 1 deletion pg_sheet_fdw.control
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
comment = 'foreign data wrapper for access to SheetReader'
default_version = '0.1'
default_version = '0.1.2'
relocatable = true
module_pathname = '$libdir/pg_sheet_fdw'