oficina / home Public

Clone
git clone https://amadan.net/oficina/home

Plain git — no account needed to clone.

Download

Download this file

1CREATE TABLE consumers (
2 consumer_id TEXT PRIMARY KEY CHECK(length(consumer_id) BETWEEN 1 AND 64 AND consumer_id NOT GLOB '*[^a-zA-Z0-9_-]*'),
3 origin TEXT NOT NULL UNIQUE CHECK(length(origin) BETWEEN 9 AND 253 AND substr(origin,1,8)='https://'),
4 app TEXT NOT NULL CHECK(length(app) BETWEEN 1 AND 32 AND app NOT GLOB '*[^a-z]*'),
5 state TEXT NOT NULL CHECK(state IN ('active','retired')),
6 created_at TEXT NOT NULL CHECK(length(created_at)=10),
7 operation_id TEXT NOT NULL CHECK(length(operation_id)=43)
8);
9-- The cap is a runaway provisioner's limit, not a scale target.
10CREATE TRIGGER consumers_cap BEFORE INSERT ON consumers
11WHEN (SELECT count(*) FROM consumers) >= 4096
12BEGIN SELECT RAISE(ABORT,'consumer registry full'); END;
13-- A retired hostname is dead at Home for good; nothing but active->retired.
14CREATE TRIGGER consumers_retire_only BEFORE UPDATE ON consumers
15WHEN OLD.state!='active' OR NEW.state!='retired' OR NEW.consumer_id IS NOT OLD.consumer_id OR NEW.origin IS NOT OLD.origin OR NEW.app IS NOT OLD.app OR NEW.created_at IS NOT OLD.created_at OR NEW.operation_id IS NOT OLD.operation_id
16BEGIN SELECT RAISE(ABORT,'consumer registry rows only retire'); END;
17CREATE TRIGGER consumers_no_delete BEFORE DELETE ON consumers
18BEGIN SELECT RAISE(ABORT,'consumer registry rows are never deleted'); END;
19CREATE TABLE operator_plans (
20 plan_id TEXT PRIMARY KEY CHECK(length(plan_id)=43 AND plan_id NOT GLOB '*[^a-zA-Z0-9_-]*'),
21 state TEXT NOT NULL UNIQUE CHECK(state IN ('pending','open')),
22 kind TEXT NOT NULL CHECK(kind IN ('create-team','add-apps','retire-apps')),
23 apps TEXT NOT NULL CHECK(length(apps) BETWEEN 1 AND 256 AND apps NOT GLOB '*[^a-z,]*'),
24 owner_index TEXT CHECK(owner_index IS NULL OR (length(owner_index)=64 AND owner_index NOT GLOB '*[^0-9a-f]*')),
25 expires_at INTEGER NOT NULL CHECK(typeof(expires_at)='integer' AND expires_at>0),
26 window_expires_at INTEGER CHECK(window_expires_at IS NULL OR (typeof(window_expires_at)='integer' AND window_expires_at>0)),
27 CHECK((kind='create-team') = (owner_index IS NOT NULL)),
28 CHECK((state='open') = (window_expires_at IS NOT NULL))
29);
30