Skip to content

feat: apply, and the artifact between plan and apply - #37

Closed
AlexeyShalaev wants to merge 1 commit into
feat/cli-read-onlyfrom
feat/cli-apply
Closed

AlexeyShalaev wants to merge 1 commit into
feat/cli-read-onlyfrom
feat/cli-apply

Conversation

@AlexeyShalaev

Copy link
Copy Markdown
Member

Part 1 of #32, second half: apply.

Destructive operations are withheld unless asked for. Without --allow-destructive, apply creates and re-attaches and retires nothing. That makes the safe behaviour the default one rather than a second mode somebody has to remember to select — and it collapses the epic's "one-shot mode and init-container mode" into one flag: the init container is just apply with nothing extra, which is exactly what running retention at application startup should not do.

The artifact:

pg-partsmith plan  -c partitions.yaml --save plan.json     # zero DDL
pg-partsmith apply -c partitions.yaml --plan plan.json --allow-destructive

Both guards from #33 stand behind it: a plan made for another table, or under a configuration since edited, is refused with exit 4 before any DDL. --allow-config-drift overrides deliberately.

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

--continue-on-error maps onto the library's own isolation, so decision 8 in the epic needed no new mechanism.

The envelope is now built by every command rather than only for JSON — it is what --save writes, and it costs nothing. The result's plan is dumped beside the result, because MaintenanceResult excludes it from serialization and an audit log wants what was done and why, not counters with nothing saying what they counted.

32 unit tests + 11 against a real PostgreSQL, including plan → save → apply and the refusal of a plan whose document has since been edited.

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