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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ they are maintained by their respective authors, and PostgreSQL Debian Group
| Extension | Description | Project URL |
| :--- | :--- | :--- |
| **[pgAudit](pgaudit)** | PostgreSQL audit extension | [https://github.com/pgaudit/pgaudit](https://github.com/pgaudit/pgaudit) |
| **[pg-jsonschema](pg-jsonschema)** | JSON Schema validation for PostgreSQL `json` and `jsonb` data | [https://github.com/supabase/pg_jsonschema](https://github.com/supabase/pg_jsonschema) |
| **[pgvector](pgvector)** | Vector similarity search for PostgreSQL | [https://github.com/pgvector/pgvector](https://github.com/pgvector/pgvector) |
| **[PostGIS](postgis)** | Geospatial database extension for PostgreSQL | [https://postgis.net/](https://postgis.net/) |

Expand Down
55 changes: 55 additions & 0 deletions pg-jsonschema/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
ARG BASE=ghcr.io/cloudnative-pg/postgresql:18-minimal-trixie
FROM $BASE AS builder

ARG PG_MAJOR
ARG EXT_VERSION
ARG PGRX_VERSION=0.16.1

USER 0

RUN set -eux; \
apt-get update; \
apt-get install -y --no-install-recommends \
ca-certificates \
curl \
git \
build-essential \
libpq-dev \
"postgresql-server-dev-${PG_MAJOR}" \
pkg-config \
cmake \
clang \
libclang-dev; \
rm -rf /var/lib/apt/lists/*

ENV PATH=/root/.cargo/bin:${PATH}

RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --no-modify-path --profile minimal --default-toolchain stable
RUN cargo install cargo-pgrx --version "${PGRX_VERSION}" --locked
RUN cargo pgrx init --pg"${PG_MAJOR}"=/usr/lib/postgresql/"${PG_MAJOR}"/bin/pg_config

WORKDIR /tmp
RUN set -eux; \
curl -fsSL -o pg_jsonschema.tar.gz "https://github.com/supabase/pg_jsonschema/archive/refs/tags/v${EXT_VERSION}.tar.gz"; \
tar -xzf pg_jsonschema.tar.gz; \
mv "pg_jsonschema-${EXT_VERSION}" pg_jsonschema

WORKDIR /tmp/pg_jsonschema
RUN set -eux; \
cargo pgrx install --release --no-default-features --features "pg${PG_MAJOR}" --pg-config /usr/lib/postgresql/"${PG_MAJOR}"/bin/pg_config

RUN install -D -m 0644 /tmp/pg_jsonschema/LICENSE /licenses/pg_jsonschema/LICENSE

FROM scratch
ARG PG_MAJOR

# Licenses
COPY --from=builder /licenses /licenses/

# Libraries
COPY --from=builder /usr/lib/postgresql/${PG_MAJOR}/lib/pg_jsonschema.so /lib/

# Share
COPY --from=builder /usr/share/postgresql/${PG_MAJOR}/extension/pg_jsonschema* /share/extension/

USER 65532:65532
65 changes: 65 additions & 0 deletions pg-jsonschema/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# pg_jsonschema

[pg_jsonschema](https://github.com/supabase/pg_jsonschema) is a PostgreSQL
extension that adds JSON Schema validation for `json` and `jsonb` data.

This image provides a convenient way to deploy and manage `pg_jsonschema` with
[CloudNativePG](https://cloudnative-pg.io/).

## Usage

### 1. Add the extension image to your Cluster

Define the `pg-jsonschema` extension under the `postgresql.extensions` section
of your `Cluster` resource. For example:

```yaml
apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
name: cluster-pg-jsonschema
spec:
imageName: ghcr.io/cloudnative-pg/postgresql:18-minimal-trixie
instances: 1

storage:
size: 1Gi

postgresql:
extensions:
- name: pg-jsonschema
image:
# renovate: datasource=github-tags depName=supabase/pg_jsonschema versioning=semver extractVersion=^v(?<version>.*)$
reference: ghcr.io/cloudnative-pg/pg-jsonschema:0.3.4-18-trixie
```

### 2. Enable the extension in a database

Create or update a `Database` resource to install the extension in a specific
database:

```yaml
apiVersion: postgresql.cnpg.io/v1
kind: Database
metadata:
name: cluster-pg-jsonschema-app
spec:
name: app
owner: app
cluster:
name: cluster-pg-jsonschema
extensions:
- name: pg_jsonschema
# renovate: datasource=github-tags depName=supabase/pg_jsonschema versioning=semver extractVersion=^v(?<version>.*)$
version: "0.3.4"
```

### 3. Verify installation

Once the database is ready, connect to it with `psql` and run:

```sql
\dx
```

You should see `pg_jsonschema` listed among the installed extensions.
22 changes: 22 additions & 0 deletions pg-jsonschema/metadata.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
metadata = {
name = "pg-jsonschema"
sql_name = "pg_jsonschema"
image_name = "pg-jsonschema"
shared_preload_libraries = []
extension_control_path = []
dynamic_library_path = []
ld_library_path = []
auto_update_os_libs = false
required_extensions = []

versions = {
bookworm = {
// renovate: datasource=github-tags depName=supabase/pg_jsonschema versioning=semver extractVersion=^v(?<version>.*)$
"18" = "0.3.4"
}
trixie = {
// renovate: datasource=github-tags depName=supabase/pg_jsonschema versioning=semver extractVersion=^v(?<version>.*)$
"18" = "0.3.4"
}
}
}