-- What somebody wants a module's configuration to say on a node. -- -- Managed files are generated and never edited (novox/hq ADR 0011), so an intention about one has -- to live somewhere the generator can see it. This is that place: the file is produced from the -- module's defaults and these together, and the module can rewrite its half freely. create table settings ( -- Null means the whole mesh. Two layers, and both wanted from the start: "every machine -- running this gets that" and "this one differs" are different statements, and expressing the -- second by repeating the first would pin everything it restated against future changes. node uuid references node(id) on delete cascade, module text not null references module(name) on delete cascade, values jsonb not null, set_at timestamptz not null default now() ); -- One row per layer per module. A partial index for each half, because null is not equal to null -- and a plain unique constraint would let the mesh-wide layer be written twice. create unique index settings_for_the_mesh on settings (module) where node is null; create unique index settings_for_a_node on settings (node, module) where node is not null; -- Settings go when their module does, unlike assignments, which hold a module in place. A setting -- for a module nobody has is not something a machine is running -- it is a note about a thing that -- no longer exists, and keeping it would mean the mesh reporting settings that can never apply.