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
15 changes: 13 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,22 @@ on:
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
pg: [pg15, pg17]
steps:
- uses: actions/checkout@v4
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build docker image
env:
BASE_IMAGE: ghcr.io/${{ github.repository_owner }}/pg-debyte-ci-base:latest
run: ./scripts/docker-ci-build-image.sh
- name: Build workspace packages
run: ./scripts/docker-ci-build-workspace.sh
run: bash -lc "source scripts/dev.sh; docker_build_workspace ${{ matrix.pg }}"
- name: Build README examples
run: ./scripts/docker-ci-build-examples.sh
run: bash -lc "source scripts/dev.sh; docker_build_examples ${{ matrix.pg }}"
35 changes: 35 additions & 0 deletions .github/workflows/docker-base-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: docker-base-image

on:
push:
branches:
- main
workflow_dispatch:

permissions:
contents: read
packages: write

jobs:
build-base:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push base image
uses: docker/build-push-action@v6
with:
context: .
file: docker/ci-base.Dockerfile
push: true
tags: |
ghcr.io/${{ github.repository_owner }}/pg-debyte-ci-base:latest
ghcr.io/${{ github.repository_owner }}/pg-debyte-ci-base:${{ github.sha }}
35 changes: 33 additions & 2 deletions .github/workflows/pg-extension-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,43 @@ jobs:
pg-extension-tests:
runs-on: ubuntu-latest
timeout-minutes: 20
strategy:
matrix:
pg: [pg15, pg17]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build docker image
env:
BASE_IMAGE: ghcr.io/${{ github.repository_owner }}/pg-debyte-ci-base:latest
run: ./scripts/docker-ci-build-image.sh
- name: PGRX tests (pg_debyte_ext)
run: ./scripts/docker-ci-test-pg-extension.sh
run: bash -lc "source scripts/dev.sh; docker_tests_pg_extensions ${{ matrix.pg }}"

pgrx-workspace-tests:
runs-on: ubuntu-latest
timeout-minutes: 20
strategy:
matrix:
pg: [pg15, pg17]
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build docker image
env:
BASE_IMAGE: ghcr.io/${{ github.repository_owner }}/pg-debyte-ci-base:latest
run: ./scripts/docker-ci-build-image.sh
- name: Workspace tests (include pg_debyte_pgrx)
run: docker run --rm -t pg-debyte-ci bash -lc "/usr/local/cargo/bin/cargo test --workspace --exclude pg_debyte_ext"
run: bash -lc "source scripts/dev.sh; docker_tests_workspace ${{ matrix.pg }}"
43 changes: 32 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# pg-debyte

[![Build](https://github.com/Xaneets/pg-debyte/actions/workflows/build.yml/badge.svg)](https://github.com/Xaneets/pg-debyte/actions/workflows/build.yml)
[![Workspace tests](https://github.com/Xaneets/pg-debyte/actions/workflows/core-tests.yml/badge.svg)](https://github.com/Xaneets/pg-debyte/actions/workflows/core-tests.yml)
[![PG extension tests](https://github.com/Xaneets/pg-debyte/actions/workflows/pg-extension-tests.yml/badge.svg)](https://github.com/Xaneets/pg-debyte/actions/workflows/pg-extension-tests.yml)
[![Build pg15/pg17](https://github.com/xaneets/pg-debyte/actions/workflows/build.yml/badge.svg?label=build%20pg15%2Fpg17)](https://github.com/xaneets/pg-debyte/actions/workflows/build.yml)
[![Core tests](https://github.com/xaneets/pg-debyte/actions/workflows/core-tests.yml/badge.svg?label=core%20tests)](https://github.com/xaneets/pg-debyte/actions/workflows/core-tests.yml)
[![PG extension tests pg15/pg17](https://github.com/xaneets/pg-debyte/actions/workflows/pg-extension-tests.yml/badge.svg?label=pg%20ext%20tests%20pg15%2Fpg17)](https://github.com/xaneets/pg-debyte/actions/workflows/pg-extension-tests.yml)
[![Crates.io](https://img.shields.io/crates/v/pg_debyte_core.svg)](https://crates.io/crates/pg_debyte_core)

Core building blocks for PostgreSQL extensions that decode `bytea` into JSON.
Expand All @@ -12,7 +12,7 @@ This repository provides reusable Rust crates plus a small example extension.

- `pg_debyte_core`: envelope parser, registry, codecs/actions, limits, errors.
- `pg_debyte_macros`: helper macros for registering typed decoders.
- `pg_debyte_pgrx`: PG17-only helper glue (GUC limits and decoding helpers).
- `pg_debyte_pgrx`: PG15/PG17 helper glue (GUC limits and decoding helpers).
- `pg_debyte_ext`: example PG17 extension crate with a demo registry and decoder.
- `pg_debyte_tools`: helper binaries (demo payload generator).

Expand All @@ -23,12 +23,13 @@ This repository provides reusable Rust crates plus a small example extension.
- Bincode codec with size limits.
- Static registry for decoders/codecs/actions.
- Known schema SQL functions (per-type decoding without envelope).
- PG17-only helper for GUC limits and decoding (to be called from extension).
- PG15/PG17 helper for GUC limits and decoding (to be called from extension).
- Panic protection around decoding (catch_unwind in pgrx).

## Notes

- `pg_debyte_ext` is only an example implementation; you will create your own extension crate.
- PG15 support will be added later as a separate focus.
- PG15/PG17 are supported via pgrx feature flags.

## Examples

Expand All @@ -49,14 +50,28 @@ cd my_pg_debyte_ext
```toml
[dependencies]
pgrx = { version = "0.16.1", default-features = false, features = ["pg17"] }
# or: features = ["pg15"]
pg_debyte_core = "0.2.0"
pg_debyte_macros = "0.2.0"
pg_debyte_pgrx = "0.2.0"
pg_debyte_pgrx = { version = "0.2.0", default-features = false }
serde = { version = "1.0", features = ["derive"] }
uuid = "1.8"
```

Build and install once:
Enable the matching pg_debyte_pgrx feature:

```toml
[features]
pg15 = ["pg_debyte_pgrx/pg15"]
pg17 = ["pg_debyte_pgrx/pg17"]
```

Build and install once (choose your PG major, matching features):

```bash
cargo pgrx init --pg15 /path/to/pg15
cargo pgrx install --features pg15 --sudo
```

```bash
cargo pgrx init --pg17 /path/to/pg17
Expand Down Expand Up @@ -267,9 +282,14 @@ cargo run -p pg_debyte_tools --bin demo_envelope
SELECT bytea_to_json_auto(decode('<hex-encoded-envelope>', 'hex'));
```

## Example usage (PG17)
## Example usage (PG15/PG17)

Build and install the example extension (PG15/PG17):

Build and install the example extension:
```bash
cargo pgrx init --pg15 /path/to/pg15
cargo pgrx install -p pg_debyte_ext --features pg15 --sudo
```

```bash
cargo pgrx init --pg17 /path/to/pg17
Expand Down Expand Up @@ -335,5 +355,6 @@ cargo run -p pg_debyte_tools --bin demo_auto_sql
If host permissions make `cargo pgrx test` difficult, use the Docker runner:

```bash
./scripts/docker-ci-test-pg-extension.sh
source scripts/dev.sh
docker_tests_pg_extensions pg17
```
39 changes: 39 additions & 0 deletions docker/ci-base.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
FROM postgres:17

USER root

RUN apt-get update \
&& apt-get install -y --no-install-recommends \
ca-certificates \
clang \
curl \
git \
llvm-dev \
libclang-dev \
build-essential \
pkg-config \
bison \
flex \
libicu-dev \
libreadline-dev \
libssl-dev \
libxml2-dev \
libxslt1-dev \
liblz4-dev \
libzstd-dev \
zlib1g-dev \
&& rm -rf /var/lib/apt/lists/*

ENV RUSTUP_HOME=/usr/local/rustup
ENV CARGO_HOME=/usr/local/cargo
ENV PATH=/usr/local/cargo/bin:$PATH
ENV USER=postgres
ENV LOGNAME=postgres
ENV HOME=/var/lib/postgresql

RUN curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain stable
RUN cargo install cargo-pgrx --version 0.16.1 --locked

USER postgres
RUN cargo pgrx init --pg17 download
RUN cargo pgrx init --pg15 download
40 changes: 3 additions & 37 deletions docker/ci.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,44 +1,10 @@
FROM postgres:17

USER root

RUN apt-get update \
&& apt-get install -y --no-install-recommends \
ca-certificates \
clang \
curl \
git \
llvm-dev \
libclang-dev \
build-essential \
pkg-config \
bison \
flex \
libicu-dev \
libreadline-dev \
libssl-dev \
libxml2-dev \
libxslt1-dev \
liblz4-dev \
libzstd-dev \
zlib1g-dev \
&& rm -rf /var/lib/apt/lists/*

ENV RUSTUP_HOME=/usr/local/rustup
ENV CARGO_HOME=/usr/local/cargo
ENV PATH=/usr/local/cargo/bin:$PATH
ENV USER=postgres
ENV LOGNAME=postgres
ENV HOME=/var/lib/postgresql

RUN curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain stable
RUN cargo install cargo-pgrx --version 0.16.1 --locked
ARG BASE_IMAGE=pg-debyte-ci-base
FROM ${BASE_IMAGE}

WORKDIR /workspace
COPY . /workspace
USER root
RUN chown -R postgres:postgres /workspace /usr/local/rustup /usr/local/cargo

USER postgres
RUN cargo pgrx init --pg17 download

CMD ["bash", "-lc", "env -u PG_VERSION -u PG_MAJOR /usr/local/cargo/bin/cargo pgrx test -p pg_debyte_ext --features pg17"]
7 changes: 4 additions & 3 deletions examples/readme_by_id/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ publish = false
crate-type = ["cdylib", "lib"]

[features]
default = ["pg17"]
pg17 = ["pgrx/pg17"]
default = []
pg15 = ["pgrx/pg15", "pg_debyte_pgrx/pg15"]
pg17 = ["pgrx/pg17", "pg_debyte_pgrx/pg17"]

[dependencies]
pgrx = { version = "0.16.1", default-features = false }
pg_debyte_core = { version = "0.2.0", path = "../../pg_debyte_core" }
pg_debyte_macros = { version = "0.2.0", path = "../../pg_debyte_macros" }
pg_debyte_pgrx = { version = "0.2.0", path = "../../pg_debyte_pgrx" }
pg_debyte_pgrx = { version = "0.2.0", path = "../../pg_debyte_pgrx", default-features = false }
serde = { version = "1.0", features = ["derive"] }
uuid = "1.8"
7 changes: 4 additions & 3 deletions examples/readme_envelope/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ publish = false
crate-type = ["cdylib", "lib"]

[features]
default = ["pg17"]
pg17 = ["pgrx/pg17"]
default = []
pg15 = ["pgrx/pg15", "pg_debyte_pgrx/pg15"]
pg17 = ["pgrx/pg17", "pg_debyte_pgrx/pg17"]

[dependencies]
pgrx = { version = "0.16.1", default-features = false }
pg_debyte_core = { version = "0.2.0", path = "../../pg_debyte_core" }
pg_debyte_macros = { version = "0.2.0", path = "../../pg_debyte_macros" }
pg_debyte_pgrx = { version = "0.2.0", path = "../../pg_debyte_pgrx" }
pg_debyte_pgrx = { version = "0.2.0", path = "../../pg_debyte_pgrx", default-features = false }
serde = { version = "1.0", features = ["derive"] }
uuid = "1.8"
7 changes: 4 additions & 3 deletions examples/readme_known_schema/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ publish = false
crate-type = ["cdylib", "lib"]

[features]
default = ["pg17"]
pg17 = ["pgrx/pg17"]
default = []
pg15 = ["pgrx/pg15", "pg_debyte_pgrx/pg15"]
pg17 = ["pgrx/pg17", "pg_debyte_pgrx/pg17"]

[dependencies]
pgrx = { version = "0.16.1", default-features = false }
pg_debyte_core = { version = "0.2.0", path = "../../pg_debyte_core" }
pg_debyte_macros = { version = "0.2.0", path = "../../pg_debyte_macros" }
pg_debyte_pgrx = { version = "0.2.0", path = "../../pg_debyte_pgrx" }
pg_debyte_pgrx = { version = "0.2.0", path = "../../pg_debyte_pgrx", default-features = false }
serde = { version = "1.0", features = ["derive"] }
uuid = "1.8"
4 changes: 2 additions & 2 deletions pg_debyte_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ authors = ["Dmitriy Sergeev <xaneets@gmail.com>"]
description = "Core building blocks for PostgreSQL extensions that decode bytea into JSON"
license = "Apache-2.0"
readme = "../README.md"
repository = "https://github.com/Xaneets/pg-debyte"
homepage = "https://github.com/Xaneets/pg-debyte"
repository = "https://github.com/xaneets/pg-debyte"
homepage = "https://github.com/xaneets/pg-debyte"
keywords = ["postgres", "postgresql", "bytea", "json", "pgrx"]
categories = ["database", "encoding"]

Expand Down
2 changes: 2 additions & 0 deletions pg_debyte_core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ pub enum DecodeError {
Json(String),
#[error("io error: {0}")]
Io(String),
#[error("panic during decode: {0}")]
Panic(String),
}

impl From<serde_json::Error> for DecodeError {
Expand Down
11 changes: 6 additions & 5 deletions pg_debyte_ext/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ version = "0.1.0"
edition = "2021"
publish = false
authors = ["Dmitriy Sergeev <xaneets@gmail.com>"]
description = "Example pg_debyte PostgreSQL extension for PG17"
description = "Example pg_debyte PostgreSQL extension for PG15/PG17"
license = "Apache-2.0"
readme = "../README.md"
repository = "https://github.com/Xaneets/pg-debyte"
homepage = "https://github.com/Xaneets/pg-debyte"
repository = "https://github.com/xaneets/pg-debyte"
homepage = "https://github.com/xaneets/pg-debyte"

[lib]
crate-type = ["cdylib", "lib"]
Expand All @@ -18,12 +18,13 @@ name = "pgrx_embed_pg_debyte_ext"
path = "./src/bin/pgrx_embed.rs"

[features]
pg17 = ["pgrx/pg17", "pgrx-tests/pg17"]
pg15 = ["pgrx/pg15", "pgrx-tests/pg15", "pg_debyte_pgrx/pg15"]
pg17 = ["pgrx/pg17", "pgrx-tests/pg17", "pg_debyte_pgrx/pg17"]
pg_test = []

[dependencies]
pg_debyte_core = { version = "0.2.0", path = "../pg_debyte_core" }
pg_debyte_pgrx = { version = "0.2.0", path = "../pg_debyte_pgrx" }
pg_debyte_pgrx = { version = "0.2.0", path = "../pg_debyte_pgrx", default-features = false }
pg_debyte_macros = { version = "0.2.0", path = "../pg_debyte_macros" }
serde = { version = "1.0", features = ["derive"] }
uuid = "1.8"
Expand Down
Loading