-- Proxy pool: stored candidates for the global egress proxy (#545). Global -- configuration: the table is not part of a task archive. -- -- An entry only ever chooses the existing global proxy; it adds no egress path -- of its own. This migration stores entries; nothing activates one yet. -- -- address is sealed at rest by db/secrets.go (AAD "proxy_pool.address"): it may -- carry user:pass. Because sealing is randomized, uniqueness is enforced on -- address_hash, an HMAC of the normalized address under a sub-key of the secret -- key (db/proxy_pool.go), recomputed when the key is rotated. -- -- At most one entry is active, and the active entry is enabled. -- egress_ip, last_check_at and last_check_ok are written by the health check; -- NULL means never checked. CREATE TABLE IF NOT EXISTS proxy_pool ( id BIGSERIAL PRIMARY KEY, label TEXT NOT NULL CHECK (length(btrim(label)) > 0), address TEXT NOT NULL, address_hash TEXT NOT NULL, enabled BOOLEAN NOT NULL DEFAULT true, active BOOLEAN NOT NULL DEFAULT false, egress_ip TEXT, last_check_at TIMESTAMPTZ, last_check_ok BOOLEAN, created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), CONSTRAINT proxy_pool_address_hash_key UNIQUE (address_hash), CONSTRAINT proxy_pool_active_enabled CHECK (NOT active OR enabled) ); CREATE UNIQUE INDEX IF NOT EXISTS proxy_pool_one_active ON proxy_pool ((true)) WHERE active; DROP TRIGGER IF EXISTS trg_proxy_pool_upd ON proxy_pool; CREATE TRIGGER trg_proxy_pool_upd BEFORE UPDATE ON proxy_pool FOR EACH ROW EXECUTE FUNCTION set_updated_at();