Skip to content

feat: a command line for the read-only half - #36

Closed
AlexeyShalaev wants to merge 2 commits into
feat/partitions-documentfrom
feat/cli-read-only
Closed

AlexeyShalaev wants to merge 2 commits into
feat/partitions-documentfrom
feat/cli-read-only

Conversation

@AlexeyShalaev

Copy link
Copy Markdown
Member

Part 1 of #32: the CLI, read-only half.

pip install "pg-partsmith[cli]" gives pg-partsmith inspect / plan / validate over a document and a DSN. 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:

Code Meaning
0 nothing pending
2 drift under plan --check — what "maintenance has stopped running" looks like
3 findings; outranks drift, because a run fixes drift and cannot fix a finding
4 configuration
5 connection
6 another maintainer holds the lock
1 unexpected

6 is deliberately not a failure: two runs overlapping is ordinary operation, and reporting it as an error is the first false page every deployment gets.

--output json is the models' own dump under a versioned envelope, by_alias=True, so what comes out of plan and what goes into a document are one vocabulary. Logs go to stderr. DSN precedence is --dsn → $PG_PARTSMITH_DSN → the document, so a mounted ConfigMap can carry the tables while the password stays in a secret.

argparse rather than a dependency: the image this ships in is measured, and a nicer --help is a poor trade for a wheel.

The integration tests caught a real bug: a refused connection arrives as a bare OSError (asyncpg raises it before SQLAlchemy has a DBAPI error to wrap), which would have been exit 1 instead of 5.

23 unit tests + 7 against a real PostgreSQL. Stacked on the document PR.

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.
@AlexeyShalaev

Copy link
Copy Markdown
Member Author

Folded into #43, one PR for the whole epic; this branch stays for history.

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.

1 participant