Files
mesh-controller/internal/inventory/migrations/0104-the-chain-moves-to-the-bus.sql
T
jschoubben 0e4feb0d3a Keep assignments in the assignments bucket and move the rows there at start (issue 1093)
Once chain_moved records the kind, Assign, Unassign and Assigned write and read the keys <node>.<module>, and every join of the store that read assignments is made from the bucket: where a module runs, what is behind, what a machine awaits, a given value due for replacement, taking a module, and whether a module may be forgotten (refused while a standing assignment names it). An unassignment ends the key with a marker and keeps its earlier values, as it removed the row; no ended or pending mark is written yet. The generation rises with each change, and a seat held by an assignment goes with it: the foreign key from seat_holding is dropped by migration 0104 and the controller says both. The provisioner's plan is kept in the values by a pass of the tick that writes that one field by compare-and-set; the assignment-changed event is said from what the bucket holds, whoever wrote it. The start moves the rows with what each machine was last sent, keeping a plan the mirror put in a value.
2026-10-18 03:15:44 +02:00

22 lines
1.5 KiB
SQL

-- Builds, rollouts and assignments move to the bus (novox/hq ADR 0408 §8, design 47 milestone 5, issue 1089).
--
-- This migration makes the switch alone. The rows of build, build_request, release_plan, batched_merge, assignment and
-- pending_assignment are written into the chain's buckets by the serving controller at its start, holding the lease,
-- because a migration runs when the store is opened, before any connection to the bus. This row is the switch: while it
-- is absent nothing reads the buckets; once the move has counted every row against the keys it wrote, it is written, and
-- nothing reads the tables. One row at most; never written by a migration, so a delivery alone changes nothing. The
-- controller keeps no consolidated schema, so this migration is the whole of the change; the tables go by a later one.
create table chain_moved (
only_one boolean primary key default true check (only_one),
moved_at timestamptz not null default now(),
-- The counts the move read from the tables and wrote as keys, per kind, and the largest value it wrote: what a
-- reader of the move reads back.
counts jsonb not null,
largest jsonb not null
);
-- A seat's holder was an assignment by a foreign key; the assignments are keys of the bus once moved, so the controller says
-- it (HoldSeat refuses a holder that is not assigned) and an unassignment takes the holding with it (Unassign), as the
-- key's `on delete cascade` did.
alter table seat_holding drop constraint seat_holding_node_module_fkey;