-- Which port a machine uses for what a module needs reachable. -- -- novox/hq ADR 0038. A module cannot choose this: it is written once and assigned anywhere, so any -- number it picks is a guess about a machine it has never seen. Two modules guessing the same one -- is not a mistake either of them made -- it is a database module meeting the mesh's own store and -- being told, by a container runtime three layers down, that the port is already allocated. -- -- **Made once and kept**, exactly as a credential is. A port that moved on every declaration would -- restart both ends each time, and would hand a consumer a number that was true when it was read. create table port_assignment ( node uuid not null references node(id) on delete cascade, module text not null references module(name) on delete cascade, -- The port the software itself uses -- what a module writes down, and the only part it knows. wanted integer not null, -- What the machine publishes it on. The same as `wanted` when the protocol fixes it. machine integer not null, -- Whether the protocol fixed it. Kept rather than derived: *this is 25 because it must be* -- and *this is 25 because it was free* are different facts, and only the first refuses a -- second holder. fixed boolean not null default false, assigned_at timestamptz not null default now(), primary key (node, module, wanted), -- **One machine port, one holder.** The constraint is the point: a second module cannot be -- given a port the first has, and finding that out here is finding it out at assignment -- rather than at apply. unique (node, machine) );