Skip to content

feat: a CLI, an image, and hooks reachable from a config file (#32) - #43

Merged
AlexeyShalaev merged 37 commits into
masterfrom
feat/cli-and-container
Sep 2, 2026
Merged

AlexeyShalaev merged 37 commits into
masterfrom
feat/cli-and-container

Conversation

@AlexeyShalaev

@AlexeyShalaev AlexeyShalaev commented Sep 2, 2026 •

Copy link
Copy Markdown
Member

Closes #32. The toolkit is the construction helper from #27, which 1.1.0 closed.

Eleven commits, one per piece, in the order the epic's own "Order" section asks for. Read it commit by commit — each message says what it does and why — or start from the three operator pages, which is what a Go team evaluating this would read first: docs/guide/cli.md, docs/guide/container.md, docs/guide/hooks-in-config.md.

What is in it, by epic part

Commit Epic part What
aa4ce6c — (prerequisite) apply() refuses a plan the configuration did not produce: config_fingerprint, PlanConfigMismatchError, cursors typed
2da5a30 #27, second half PartitionToolkit.from_engine — the three settings that live on two objects, given once
385424f Part 1 PartitionsDocument: several tables, defaults, runtime; PartitionTableSettings is now the same field list read from the environment
1a377d9 58856f1 Part 1 pg-partsmith inspect / plan / validate, exit codes, --output json as the model dump
0690659 Part 1 apply, creations-only by default; plan --save / apply --plan as the artifact between them
0e0fe86 Part 2 ghcr.io/bedrock-python/pg-partsmith: non-root, size budget and scan in CI, published from the release workflow, never latest
5bb3bef Part 3b CommandHooks and the document's hooks section, under --allow-hooks
f349b82 — (extra) --output metrics: Prometheus text for a node_exporter textfile
34cbcf1 — (extra) capabilities and is_destructive in the plan dump; plan --locks; why there is no --sql
HEAD Part 3a PythonHooks: a block of Python where a command would go, compiled by validate

The decisions, as taken

  1. Format — YAML canonical, JSON free, TOML skipped. The document model is the contract, not the syntax.
  2. Extra — cli, in the same distribution, carrying PyYAML and asyncpg.
  3. apply safety — not TTY-gated (a container has no TTY). Destructive operations are withheld unless --allow-destructive, which collapses part 2's two modes into one flag: the init container is apply with nothing extra.
  4. Driver — asyncpg; postgresql:// is upgraded to it, an explicit driver is left alone.
  5. First surface — the read-only half is its own commit and was deployable on its own.
  6. 3a / 3b — both, 3b first. The epic's blocker (Still open after 1.0.0: a construction helper, and what hooks are handed #27 Option A) had already shipped in 1.1, which made 3b nearly free and moved the toolkit from step 4 to step 1.
  7. Snippet namespace — event and log. No database handle: "read-only" is not something a connection with DDL rights can promise, and SqlPredicate already answers that need on the plan side.
  8. Hook failure — the library's own isolation; the CLI exposes --continue-on-error.

Two things the epic assumed that did not hold, both now stated in the docs: plan does run configured SQL (SqlPredicate), and the plan artifact needed guarding before it existed.

Exit codes

0 nothing pending · 2 drift under plan --check · 3 findings or run issues (outranks drift: a run fixes drift and cannot fix a finding) · 4 configuration · 5 connection · 6 lock held (ordinary operation, not a page) · 1 unexpected.

Verified

2664 unit tests; 553 integration tests against real PostgreSQL, including the CLI end to end (plan → save → apply, a refused stale plan, a command hook and a Python hook around a real DROP, a refusing hook leaving the partition in place). ruff, format and mypy clean. Image built and run locally: 244 MB, budget 280 MB, non-root, --version matches.

Still open

Only the -r1 image-revision scheme for base-image CVE rebuilds, which needs deciding before the first one and not before.

The ten stacked PRs (#33–#42) this folds together are closed with a pointer here; their branches stay for history.

plan() and apply() were separable, but nothing checked that the plan handed
to apply() was the one this configuration produced. In one process that pair
cannot disagree; written to a file by one run and read by another -- the
reason the split exists -- it can.

A plan now records the fingerprint of the configuration it was planned under,
and apply() refuses a plan made for another table, or one made under a
configuration that has since been edited, before any DDL runs. The identity
revalidation each destructive operation already did answers whether this is
still the same relation, not whether it is still the same intent.

cursors is typed dict[str, int]: only an integer axis records one, and Any
meant a plan written to JSON did not always read back as the plan written.
Three settings live on two objects and have to agree: marker_prefix, which
one writes and the other looks for; ddl_timezone, which one writes naive
boundary literals in and the other reads them back in -- on constructors
that do not even default to the same value -- and boundary_codec. Passing
one of them to one object only is silent: detached partitions simply stop
being seen, so they are never dropped.

PartitionToolkit.from_engine takes each of those once and builds the
repository, the provider, the locks, the service and the maintainer around
one engine. It returns the parts, not just a maintainer, so code calling
metadata.is_partition_closed or locks.acquire_lock directly does not build a
second set and keep it consistent by hand.
A deployment maintains several tables in one run and describes them in a
file, not in Python. PartitionsDocument is that file as a model: the tables,
the defaults they start from, and the runtime section that builds the
collaborators -- with PartitionToolkit.from_options taking it directly.

The fields a table entry takes are now one list, not two. PartitionTableSpec
holds them and PartitionTableSettings reads that same model from the
environment, so a field added once is available to a file and an environment
alike.

Unknown keys are refused wherever they appear, defaults included, where a
typo would otherwise reach every table at once; so are a document with no
tables and one relation described twice. Each of those is silent at 03:00
otherwise.

Nothing here reads a file or opens a connection: parsing belongs to whoever
owns the format.
pg-partsmith runs inspect, plan and validate over a configuration document
and a DSN, so a Go, Ruby or Node service can see its partitions without
taking a Python dependency. None of the three issues DDL, takes a lock or
fires a hook.

Exit codes are the product here, because a CronJob and a CI step read them
and nothing else: 2 is drift under plan --check, which is what maintenance
that stopped running looks like; 3 is a finding that needs a person, and
outranks drift because a run fixes drift and cannot fix a finding; 6 is a
lock another maintainer holds, which is ordinary operation and the first
false page a deployment gets if it is reported as a failure.

--output json is the models' own dump under a versioned envelope, by_alias,
so what comes out of plan and what goes into a document are one vocabulary.
Logs go to stderr. argparse rather than a dependency: the image this ships
in is measured, and a nicer --help is a poor trade for a wheel.

apply is deliberately absent. The plan/apply split is what makes an external
tool trustworthy with DROP, and the applying half ships once the artifact
between them has been used in anger.
pg-partsmith apply carries maintenance out, and withholds every destructive
operation unless --allow-destructive is given. The safe behaviour is the
default one rather than a second mode somebody has to remember to select,
which is also exactly the init-container case: create the partitions the
application is about to write into, retire nothing at startup.

plan --save writes the artifact and apply --plan reads it back, so what runs
is what was reviewed. Both guards from the first commit of this branch stand
behind it: a plan made for another table, or under a configuration that has
since been edited, is refused before any DDL, with --allow-config-drift to
override deliberately.

With no --plan, planning and applying go under one lock through maintain(),
which is also what finalizes an interrupted DETACH CONCURRENTLY before the
rest of the run is decided.

The envelope is now built by every command rather than only when JSON was
asked for: it is what --save writes, and building it costs nothing. The
result's plan is dumped beside the result because MaintenanceResult excludes
it from serialization -- an audit log wants what was done and why, not
counters with nothing saying what they counted.
ghcr.io/bedrock-python/pg-partsmith runs the CLI as its entrypoint, so a Go,
Ruby or Node service maintains its partitions from a CronJob, a Compose
service or an init container without taking a Python dependency.

Size is the first thing a team evaluating this reads, so it is a build
failure and not a note: the venv is built in a stage that is thrown away --
pip, the build backend and every __pycache__ with it -- and CI checks the
result against a budget on every pull request. It runs as UID 65532 and the
image is scanned on both the pull request and the release.

The image is published from the release workflow with the version off the
tag, as the exact version and a moving minor, and never as latest: a
scheduled job following latest would cross a major on its own, at 02:15,
with DROP in its hands. CI refuses to publish an image whose --version
disagrees with the tag it is being pushed under.

The init-container case needs no flag: apply without --allow-destructive
creates and retires nothing. The operator page states the grants this thing
needs and asks for a dedicated role, because it issues DDL and nobody should
have to work that out from the source.
…thon

A Go or Ruby team already owns an archiver; what they need is for it to be
invoked at the right moment with the right metadata. CommandHooks runs a
configured command per phase, hands it the PartitionEvent as JSON on stdin,
and treats a non-zero exit exactly as a raised exception -- the operation is
abandoned and planned again next run.

This needed no new hook context. The event has been one model for every
phase since the start of this release, so the payload is a dump of the
object a Python hook already receives, and before_drop is told the window
and the size that DETACH has already erased from the catalog.

The commands run only when the run asks for them, and a document declaring
hooks is refused rather than quietly stripped when it does not: silently
skipping a configured before_drop would let an operator read the file,
believe their archiver ran, and be wrong. No sandbox is provided and none is
claimed -- the container boundary is the honest answer, and the docs say so.

Both mirrors run the command through one blocking implementation, with the
aio side handing it to a thread. asyncio.create_subprocess_exec needs a loop
that can spawn processes, and a selector loop -- what a Windows asyncpg
deployment installs -- raises NotImplementedError instead. A hook that runs
in production and not on a developer's machine is a hook nobody trusts.
Most systems that partition PostgreSQL have no monitoring of it at all --
they find out at 03:00, from an insert PostgreSQL rejected. A CronJob
already runs this on a schedule, so the cheapest monitoring available is for
that run to leave a textfile behind.

--output metrics renders any command as Prometheus text exposition. plan
emits pending operations by kind and findings by severity, inspect the size
of the tree and the age of the oldest orphan, validate whether each table
still matches its configuration, apply what it did and what it could not.

Everything is a gauge: a one-shot job cannot own a counter, because the next
run is a new process with no memory of this one. Every run stamps
run_timestamp_seconds so a textfile nothing refreshed reads as stale rather
than as good news, and a converged table reports zeroes rather than nothing
-- a missing series and a zero are different alerts.

The numbers are read off the same envelope the JSON is, so a metric cannot
disagree with what the same run printed.
Every operation carried its capabilities -- the heaviest lock it takes and
on what, and whether it can run inside a transaction block -- as a property,
so the plan a file held had lost the one thing a DBA reads before agreeing
to a window. capabilities and is_destructive are now computed fields:
serialized on the way out, ignored on the way in, so the round trip holds
and a saved plan is reviewable for its locks without the CLI.

plan --locks prints the same for a person, one operation per line and the
lock beneath it, with the operations that cannot run inside a transaction
block marked: they are the ones a crash leaves half-done.

There is deliberately no --sql. The DDL is built at execution time from
decisions only made then -- a concurrent detach falling back to the blocking
form, rows moved out of a DEFAULT partition, an orphan marker cleared -- and
a rendering without them would be read as a transcript in exactly the cases
a review exists to catch. The plan is the contract: what, why, how big, and
what it locks.
The authentik model, for the Python-adjacent audience: a phase in a
document takes a block of Python -- inline as python, or from a file as
python_file relative to the document -- evaluated with event and log in
scope, raising to refuse. PythonHooks is the same from code, in both
mirrors, on the shared runner in pg_partsmith.python_hooks.

Every block is compiled when the document is read, and a file-backed one by
validate: a SyntaxError is a validation error with a line number in it, not
something a CronJob finds at 03:00 after some of the run's DDL has
committed. Tracebacks name the phase, or the file, rather than <string>.

It is behind the same --allow-hooks as a command, because a Python hook is
a hook and the trust argument is the same one. No sandbox is claimed: exec
with a filtered __builtins__ is not a security boundary, and the docs say
so rather than pretending otherwise. Isolation, if wanted, is a command
hook in a container of its own.

Retention predicates as Python are deliberately not in this change. They
would run during plan, not apply, which is a different gate and a different
promise about what plan is allowed to do.
Every flag is now a type annotation, the help is generated from the same
declarations that parse it, and shell completion comes with it. The image
was the reason for argparse; size turned out not to matter to the people
running this, and a typed surface does. main(argv) -> int stays, so every
test and every exit code is exactly as it was.

One bug the migration surfaced: a misspelled flag used to exit 2, the code
this tool means "drift" by, so a CronJob alerting on drift would have paged
over a typo. A usage error now exits 64, EX_USAGE from sysexits.h, and is
recognised by click's UsageError interface rather than its class: typer
vendors its copy of click from 0.27 and imports the real one before that,
so the class lives in two places across the supported versions, one of them
private. exit_code and format_message are the documented part.
@AlexeyShalaev

Copy link
Copy Markdown
Member Author

One more commit, 648260e: the command line moved from argparse to typer (size no longer being a constraint, per the discussion), with main(argv) -> int kept so every test and exit code is unchanged. Every flag is a type annotation now, help comes from the same declarations that parse it, and --install-completion works.

The migration surfaced a real bug: a misspelled flag used to exit 2, which is what this tool means "drift" by — a CronJob alerting on drift would have paged over a typo. Usage errors now exit 64 (EX_USAGE), documented in the exit-code table.

Two things worth knowing for review: typer ≥ 0.27 vendors its own copy of click (no click in the image), so usage errors are recognised by click's UsageError interface rather than by class; and the image grew from 244 to 253 MB, still under the 280 MB budget.

Unit 2667, CLI integration 17, image rebuilt and run.

Four integration tests ran maintenance at a frozen instant and then planned
with now=None -- the wall clock. Everything they asserted was true on the
day they were written and stopped being true on a calendar boundary: the
foreign-leaf grace test detaches on 2026-08-26 with a seven-day grace, so
from 2026-09-02 the wall-clock plan sees an orphan past its grace and no
GRACE_PENDING finding, and the test fails for everyone from that morning on.

Every plan now looks at the instant the run did, and the grace test looks
four days after it, inside the window it is about.
SIGTERM is what a pod is sent at its deadline, and Python's default for it
is to die on the spot: no finally, no line in the log, and under a command
hook an archiver left running unwatched. The database survived that -- a
dropped connection cancels the statement and rolls back, a session lock goes
with the session -- but "survives" is not "was told".

Both SIGTERM and Ctrl+C now cancel the run's task, which takes the path a
raised exception takes: the driver cancels the statement, the lock is
released, the engine is disposed, and the exit code is 128 + the signal --
130 or 143 -- with one line on stderr saying which. Where the loop cannot
take a signal handler (Windows, a worker thread) nothing is installed and
asyncio.run's own Ctrl+C handling applies, mapped to the same code.

A command hook's child no longer outlives the run. The wait happens in a
thread that cannot be cancelled, so the runner is split into start, finish
and stop: on cancellation the child is terminated, then killed a few seconds
later if it did not take the hint, which also ends the wait -- a Ctrl+C
during a five-minute archiver used to hang until the archiver was done.
@AlexeyShalaev

Copy link
Copy Markdown
Member Author

0204f0d: stop signals. Ctrl+C and SIGTERM — what a pod is sent at activeDeadlineSeconds — now cancel the run's task rather than killing the process: the statement in flight is cancelled and rolled back, the lock released, the engine disposed, a hook's child terminated, and the exit code is 130 / 143 with a line on stderr. Before this, SIGTERM ended the process on the spot (safe for the database, silent in the log) and Ctrl+C during a command hook hung until the hook's own timeout because the waiting thread could not be cancelled — the hook runner is now split into start / finish / stop so the child goes with the run.

Verified on a real Unix loop by probing the built image: SIGTERM → 143, SIGINT → 130, engine disposed both times. Unit 2671, CLI integration 17. Also in this branch as a cherry-pick: the test-suite time bomb fixed in #44.

One page with a copy-pasteable shape for each harness the image can run
in: plain Docker with host cron or a systemd timer; Compose as a service you
run, as the equivalent of an init container, and on a schedule with a cron
sidecar; Swarm with swarm-cronjob; Kubernetes as a Pod, a Job, a CronJob and
an init container, plus the plan-on-one-day-apply-on-another pair of Jobs
and the node_exporter textfile; GitHub Actions and GitLab CI; and the note
that anything which runs a container and reads an exit code runs this. The
image page is now about the image alone.

PG_PARTSMITH_DSN_FILE reads the connection string from a file -- the Docker
and Swarm secrets convention -- after PG_PARTSMITH_DSN and before the
document, so a Compose stack hands a secret over without a shell wrapper and
without it showing in docker inspect.
@AlexeyShalaev

Copy link
Copy Markdown
Member Author

e4239be: a deployment page — docs/guide/running.md — with a copy-pasteable shape for every harness: plain Docker (host cron, systemd timer), Compose (docker compose run behind a profile, service_completed_successfully as the init-container equivalent, a cron sidecar), Swarm (swarm-cronjob, replicas: 0, secrets and configs), Kubernetes (Pod, Job, CronJob, init container, plan-then-apply Jobs over a PVC, node_exporter textfile via hostPath, hooks in a derived image or an emptyDir), GitHub Actions and GitLab CI, and the generic-scheduler note. container.md is now about the image alone.

One small feature came out of writing it: PG_PARTSMITH_DSN_FILE, the Docker/Swarm secrets convention, read after PG_PARTSMITH_DSN and before the document. Two tests. Unit 2673, docs build clean.

examples/ holds a minimal document, one with everything in it, an
id-partitioned queue, cold tiering, and three hook scripts: a pg_dump before
a drop in bash, a webhook after a create, a COPY out before a detach as a
Python file. The test suite validates every document, compiles every hook
and syntax-checks every script, so an example that stops being right fails
a build rather than teaching the wrong vocabulary.

pg-partsmith schema prints the document's JSON Schema; with one comment line
at the top of the file an editor validates keys and completes them. The
committed copy under examples/ is checked against the generated one.

The hooks page gains the script walkthrough in bash, bash with jq, Go and
Python, and the three things every script should get right: write to a
temporary name and rename, refuse loudly on stderr, and leave the run's
connection pool alone.
@AlexeyShalaev

Copy link
Copy Markdown
Member Author

8aaa513: examples that are tested. examples/ now holds a minimal document, one with everything in it (defaults, flat table, RANGE → HASH with a composed lifecycle, a LIST root, leaves, runtime, hooks of every kind), an id-partitioned queue, cold tiering, and three hook scripts — pg_dump before a drop (bash), a webhook after a create (bash), COPY out before a detach (a python_file block). A new unit test module validates every document, compiles every hook block and bash -ns every script, so an example that stops being right fails the build.

pg-partsmith schema prints the document's JSON Schema for yaml-language-server; the committed examples/partitions.schema.json is asserted equal to the generated one. New docs page guide/examples.md; the hooks page gains a script walkthrough in bash, bash+jq, Go and Python. examples/ is excluded from ruff because the hook blocks are not modules — event and log are injected.

Unit 2683, docs build clean.

@codecov

codecov Bot commented Sep 2, 2026 •

Copy link
Copy Markdown

The Dockerfile promised that pip never reached the published image and then
shipped it inside the venv, where the CI scan found pip's vendored msgpack
with two HIGH advisories against it -- a finding an operator would have had
to explain away for a tool the image never runs. pip, setuptools and wheel
are uninstalled once the install is done; the runtime image installs nothing.
The base image ships pip too, and ensurepip carries a wheel of it; both
vendor the msgpack the scan kept reporting after the venv's own pip was
gone. They are removed by path in the runtime stage, so the step cannot
depend on which of the two the base image happens to provide, and the
image installs nothing it could have been used for.

Tests for what the unit suite had left to integration alone: the tree
renderer, inspect on a table that is not partitioned, every way a document
or a saved plan can fail to read, the sync mirrors of both hook kinds, a
hook interrupted mid-wait, a child that ignores terminate, and the metrics
fallbacks. The two branches only Windows takes are marked as such.
…ed to cover

The runtime image is distroless cc-debian12: glibc, OpenSSL, CA
certificates, a timezone database, and nothing else -- no shell, no
package manager, no pip. Python 3.14 and a pruned standard library come
from the build stage, the virtualenv is installed with uv sync --frozen
from uv.lock, extensions are stripped, bytecode is precompiled, rich is
left out, and exactly the five shared libraries the kept extension
modules link against come along. The size budget drops from 280 MB to
160; the CI image job also asserts that the imports close, that the UID
is 65532 and that there is no /bin/sh.

Two flags replace what a shell wrapper in the image used to do: --write
FILE puts any command's output in a file atomically, and apply
--ok-if-locked makes a held lock exit 0 for an init container.

Pipelines: the uv environment is cached on uv.lock and installed with
--frozen, a push cancels the run it supersedes, the image build reuses
layers across runs, published images carry an SBOM and provenance and
are signed with cosign, Dependabot watches the base images, the actions
and the lock file, and Python 3.14 joins the test matrix.
@AlexeyShalaev

AlexeyShalaev commented Sep 2, 2026 •

Copy link
Copy Markdown
Member Author

The image, rebuilt (e005587, CI green)

  • The runtime is now distroless cc-debian12:nonroot on Python 3.14: no shell, no package manager, no pip. The standard library is pruned, extensions are stripped, bytecode is precompiled, rich is left out, and exactly the five shared libraries the kept extension modules link against are staged in. The venv is installed with uv sync --frozen from uv.lock. CI measures the image at 86 MB (budget 160 MB, was 280). Trivy is clean at HIGH/CRITICAL, and the image job asserts the import closure, UID 65532 and the absence of /bin/sh.
  • Two flags replace what a shell wrapper in the image used to do: --write FILE writes any command's output to a file atomically (the node_exporter textfile), and apply --ok-if-locked makes a held lock exit 0 (an init container). The deployment docs use them; a command hook inside the image is a binary or a Python file run through /opt/venv/bin/python, and the docs say how to build an image with bash in one line.
  • Pipelines: uv cache keyed on uv.lock with --frozen installs, cancel-in-progress, buildx layer cache, SBOM + SLSA provenance, keyless cosign signing on publish (cosign verify is in the docs), Dependabot for base images / actions / lock file, Python 3.14 in the matrix.

Verified locally end-to-end against postgres:17 (validate, plan --write, apply, converge); the container starts in about half the time the previous image took.

…he bounds admit

The matrix grows in every direction that has produced a bug before. Unit
tests run on Windows, macOS and arm64 at both ends of the Python range,
and with TZ at UTC+14 and UTC-12. The integration suite runs on
PostgreSQL 18, on arm64, on Windows and macOS against a server the
runner installs itself (PG_PARTSMITH_TEST_DSN points the session at any
server; the tests that reach into the container skip), and once with
the server's clock at UTC+14 and the client's at UTC-12
(PG_PARTSMITH_TEST_PG_TZ). One job installs every direct dependency at
the lowest version pyproject.toml admits and runs both suites on it.
The wheel is built, checked and installed on its own on three
platforms, and run through to a refused connection. The image is built
and run on both architectures the release publishes. uv lock --check,
actionlint, hadolint, CodeQL, a dependency review on pull requests, and
a weekly link check round it out. Warnings are errors under pytest.

What the new checks found, fixed here:

- The declared floors were below what the code needs: pydantic 2.6 and
  typer 0.17, now stated. The committed schema is rendered by the
  pydantic in the lock; releases before 2.11 render it differently, and
  that test skips there.
- A password the server rejects was a traceback; the driver raises its
  own error before SQLAlchemy has one to wrap. It is exit 5.
- A hook command stopped mid-run had its pipes left open. They are
  closed.
- main() ran under asyncio.run, which clears the process's current loop
  on the way out; a Runner with its own loop factory leaves it alone.
- stdout and stderr replace what the console cannot encode, so an em
  dash in human output is never a traceback on an ASCII pipe.
- Test support: the foreign-leaf fixtures write instants with an
  offset, and partition bounds are read in UTC whatever the server's
  default is.
@github-advanced-security

Copy link
Copy Markdown

You are seeing this message because GitHub Code Scanning has recently been set up for this repository, or this pull request contains the workflow file for the Code Scanning tool.

What Enabling Code Scanning Means:

  • The 'Security' tab will display more code scanning analysis results (e.g., for the default branch).
  • Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results.
  • You will be able to see the analysis results for the pull request's branch on this overview once the scans have completed and the checks have passed.

For more information about GitHub Code Scanning, check out the documentation.

An unset matrix value is an empty TZ, and an empty TZ is a ZoneInfo error
to the settings that read it: the default is spelled out. A Windows runner
has a Docker daemon that cannot run a Linux container, so where the runner
brought its own PostgreSQL the Redis lock tests skip unless
PG_PARTSMITH_TEST_REDIS_URL names a server. Python 3.14 deprecates event
loop policies; the selector policy the Windows tests need is set with the
notice silenced until 3.16 takes it away. The sync package mirrors the aio
one file for file, which check-wheel-contents reads as duplicate files;
W002 is ignored. The lowest-versions job tolerates the deprecations an old
floor and a new transitive dependency raise between themselves. Dependabot
alerts, and with them the dependency graph the review action needs, are
switched on for the repository.
Under a server whose clock sits at UTC+14, thirty-five integration tests
failed, and every one of them wrote a partition bound as a bare date on a
timestamptz column: the server read the date in its own zone, the bound
landed fourteen hours off the calendar, and the library rightly called
the partition unmanaged. The fixtures now write instants with an offset,
which is what the library itself writes. The Windows package job pointed
uv at an interpreter path it does not resolve there; it is pointed at the
environment directory, which resolves everywhere.
@AlexeyShalaev

Copy link
Copy Markdown
Member Author

The checks, widened (1a55afc…ed689c4, CI green on all 28 jobs)

What runs now, beyond the unit and integration suites that were already here:

  • Platforms. Unit tests on Windows, macOS and arm64 at both ends of the Python range (3.11 and 3.14). The integration suite on PostgreSQL 15 through 18, on arm64, and on Windows and macOS against a server the runner installs itself (PG_PARTSMITH_TEST_DSN points the session at any server; the few tests that reach into the container skip; PG_PARTSMITH_TEST_REDIS_URL names a Redis where no container can run).
  • Clocks. Unit tests with TZ at UTC+14 and UTC-12, and one integration job with the server at UTC+14 and the client at UTC-12 (PG_PARTSMITH_TEST_PG_TZ).
  • Bounds. One job installs every direct dependency at the lowest version pyproject.toml admits and runs both suites on it.
  • Package. The wheel and sdist are built, checked (twine check --strict, check-wheel-contents) and installed on their own on all three platforms; the command is run through to a refused connection, on an ASCII console.
  • Image. Built and run on both architectures the release publishes, with the same budget and scan.
  • Static. uv lock --check, actionlint, hadolint, CodeQL (python + actions), a dependency review on pull requests, a weekly link check of the docs. Warnings are errors under pytest.

What the new checks found, fixed in the same commits:

  • The declared floors were below what the code needs: pydantic 2.6 and typer 0.17, now stated. The committed schema is rendered by the pydantic in the lock; releases before 2.11 render it differently, and that test skips there.
  • A password the server rejects was a traceback, not exit 5: the driver raises its own error before SQLAlchemy has one to wrap.
  • A hook command stopped mid-run had its pipes left open (a ResourceWarning in a long-lived process). They are closed.
  • main() ran under asyncio.run, which clears the process's current loop on the way out; a Runner with a loop factory leaves it as found.
  • stdout and stderr replace what the console cannot encode, so an em dash in human output is never a traceback on an ASCII pipe.
  • Under a server at UTC+14, 35 integration tests failed: every one wrote a partition bound as a bare date on a timestamptz column, which the server reads in its own zone. The library was right to call those partitions unmanaged; the fixtures now write instants with an offset, as the library itself does.

One thing to know rather than fix here: PartitionTableSettings reads its fields from unprefixed environment variables, so a host's TZ becomes the partition tz. An empty TZ (what an unset matrix value produces) is a validation error there; the workflow spells out UTC instead.

Dependabot alerts, and with them the dependency graph the review action needs, were switched on for the repository.

1.1.0 went out from master with the hook event and nothing from this
branch, so the notes written under its heading describe the next minor.
They move above the generated 1.1.0 entry under a heading of their own,
the image tag and the pinned install in the guides say 1.2, and the one
sentence that called PartitionEvent "earlier in this release" now names
the release it was.
A textfile directory a hostPath points at is root's, and the container is
not root. --write into it was a traceback and exit 1; plan --save into it
came out as "database error", because the OSError was raised inside the
run, where a bare one is read as the database's. Both are exit 4 with the
path and the reason, and a textfile a previous run wrote stays as it was.
The guides say the volume has to be writable by UID 65532.
The image job built the image, ran --version and --help, and imported the
closure; nothing ever ran it the way the guides say to. Now it is run as
a container -- read-only root filesystem, every capability dropped, the
document mounted read-only -- against a PostgreSQL container on a network
of its own, on both architectures, and the commands are the ones the
guides show, with the codes they promise: a fresh table drifts and apply
converges it, --output json is the envelope alone on stdout, --write
lands a textfile in a volume, the DSN arrives from a mounted secret, a
secret only root can read and a rejected password and hooks without
--allow-hooks each answer with their code and a sentence, SIGTERM during
a command hook is exit 143 inside the grace period with the lock
released, an overlapping run stands aside with 6, plan --save in one
container is applied by another and refused once the document changed,
an image derived with one COPY runs a Python file hook from inside, and
the Compose shape that holds an application until its partitions exist
runs as written. PG_PARTSMITH_E2E_IMAGE names the image; without it the
suite skips.

It also found that a Python block hook still running when SIGTERM
arrives holds the stop until it returns -- it runs on the loop that
handles the signal -- and past the grace period the runtime kills the
process. The guides now say so, and that work which can outlast a grace
period belongs in a command hook.
The e2e suite builds an image FROM pg-partsmith:ci, which the image job
loaded into the daemon. The buildx builder the job sets up for the cache
keeps an image store of its own and would go to the registry for that
name; BUILDX_BUILDER=default hands the test's build to the daemon's.
The release workflow built, scanned, pushed and signed the image, and
nothing looked at what a team would pull. A job after the push now does,
on both architectures: the signature by this repository's workflow
identity, the SBOM and the provenance, --version and the label against
the tag, the minor tag against the exact one, and then the end-to-end
suite against the published image itself. A failure there is a red
release run to read, not an unpublished image.
Every fenced YAML block in the guides parses, and every args or command
list that starts with one of the commands uses only the options that
command declares -- a flag renamed in the CLI would otherwise leave a
CronJob in the guide wrong with nothing to say so. The Job and CronJob
manifests the running guide shows are copied out by a script and checked
against the API schema by kubeconform on every pull request, strictly.
… looked at

A unit test on macOS failed on a ResourceWarning for an AF_UNIX socket
nobody in the test had opened. freeze_time walks every loaded module's
attributes to find the datetimes to patch; testcontainers' config module
answers a module-level __getattr__ for its deprecated names by asking the
Docker daemon for its socket path, so every frozen clock opened a docker
client -- and on a runner without Docker the SDK leaves the failed
connect's socket unclosed, which the garbage collector reports in
whatever test is running when it gets to it. Neither module holds a
clock worth freezing, so both are on freezegun's ignore list now. The
docker clients the fixtures do open are closed rather than dropped.
The release job built linux/amd64 and linux/arm64 on one amd64 runner
with no QEMU set up, and the Dockerfile's builder stage runs target-arch
binaries in every step: the first release with an image would have
uploaded to PyPI and then died on `exec format error`, with no image to
go with the library. Now each architecture is built on a machine of its
own kind -- as CI already does -- made to say its version, scanned, and
pushed by digest; only then is the package uploaded; the two tags are an
index over both digests, created and signed in one job; and the verify
job pulls the result on both architectures. A run repeated after a
failure past PyPI skips what PyPI already has. Each job asks for the
permissions it needs and no other.

The signing identity is now the release workflow on master exactly, in
the workflow and in the guide, rather than any workflow on any ref. The
builder installs with --locked, which is the flag that refuses a stale
lock; --frozen only used it. A CI run on master is left to finish.
A hook that refused, a plan gone stale, a partition still referenced --
any run that stopped on its own terms without --continue-on-error --
ended in a traceback and exit 1; it is exit 3 with the sentence, the
way --continue-on-error would have recorded it. A connection string
SQLAlchemy cannot parse, or one naming a driver that is not installed,
was reported as the database's fault with exit 5; it is exit 4. A
runtime.boundary_codec nothing resolves, and an empty command vector,
passed validate and surfaced as a bare ValueError at apply; both are
refused where they are written, with the field named. A command hook on
a table partitioned by a sequence crashed the run building the hook's
environment, because a window edge there is a number and not a moment.
The console script is registered by the package itself, so a bare
`pip install pg-partsmith` puts `pg-partsmith` on PATH and it died with
a ModuleNotFoundError; it now goes through pg_partsmith.console, which
says what to install and exits 64, and the package job proves it. The
--help epilog names 130 and 143, --dsn's help names the file the DSN
can come from, and the lock-prefix comment sits over the lock prefix.
…e for what 1.2.0 adds

The changelog and the container guide described a previous image --
Debian userland, 280 MB, a slower start -- that was never released;
1.2.0 is the first image, and the prose now describes it on its own.
The guides said `uv sync --frozen` refuses a stale lock, which only
--locked does, and the builder now runs with --locked. Exit 5 is "the
database" rather than "connection", which is what the code has meant
all along: a refused password or a failed statement lands there too.
The plan-then-apply recipe pointed at `kubectl cp`, which needs a tar
the image does not have. The README and the installation page did not
mention the cli extra, said PostgreSQL 15, 16 and 17 where CI runs 15
through 18, and a concepts page counted six hooks where there are eight.
The API reference gains the document models, the hook event, the
toolkit, the command and Python hooks, and the plan guard.

The Dockerfile names its base images in the FROM lines, where Dependabot
reads them, instead of through build arguments it cannot follow; it also
drops the zstd module whose library the runtime never carried, greenlet's
tests, and the two console scripts rich's dependencies left behind. The
Compose test's healthcheck probes over TCP, which cannot pass before the
server listens. toolkit.py is a mechanical mirror and is listed as one;
the hook modules are not, and are listed as hand-maintained.
@AlexeyShalaev
AlexeyShalaev merged commit 34fb9ba into master Sep 2, 2026
32 checks passed
@AlexeyShalaev
AlexeyShalaev deleted the feat/cli-and-container branch September 6, 2026 07:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Epic: standalone CLI and container image for partition maintenance

2 participants