Files
rust-discovery/migrations/0014_windows_msi_catalog.sql
T
2026-11-14 12:04:36 +01:00

28 lines
1.6 KiB
SQL

-- Additive immutable tenant catalog; existing APT recipes/artifact semantics stay.
ALTER TABLE artifacts ADD CONSTRAINT artifacts_tenant_identity_digest
UNIQUE (tenant_id,artifact_id,sha256,size_bytes);
CREATE TABLE windows_msi_recipes (
tenant_id uuid NOT NULL REFERENCES tenants,
catalog_id uuid NOT NULL,
recipe_id text NOT NULL CHECK(recipe_id IN ('rmm-windows-msi-fixture-install-1.0','rmm-windows-msi-fixture-upgrade-1.1')),
recipe_version text NOT NULL CHECK(recipe_version='1'),
recipe_sha256 text NOT NULL CHECK(recipe_sha256 ~ '^[0-9a-f]{64}$'),
artifact_id uuid NOT NULL,
artifact_sha256 text NOT NULL CHECK(artifact_sha256 ~ '^[0-9a-f]{64}$'),
artifact_bytes bigint NOT NULL CHECK(artifact_bytes BETWEEN 1 AND 262144),
payload bytea NOT NULL CHECK(octet_length(payload) BETWEEN 1 AND 65536),
created_at timestamptz NOT NULL DEFAULT now(),
PRIMARY KEY(tenant_id,catalog_id),
UNIQUE(tenant_id,recipe_id,recipe_version), UNIQUE(tenant_id,recipe_sha256),
FOREIGN KEY(tenant_id,artifact_id,artifact_sha256,artifact_bytes)
REFERENCES artifacts(tenant_id,artifact_id,sha256,size_bytes)
);
ALTER TABLE windows_msi_recipes ENABLE ROW LEVEL SECURITY;
ALTER TABLE windows_msi_recipes FORCE ROW LEVEL SECURITY;
CREATE POLICY tenant_scope ON windows_msi_recipes
USING (tenant_id::text=current_setting('app.tenant_id',true))
WITH CHECK (tenant_id::text=current_setting('app.tenant_id',true));
GRANT SELECT, INSERT ON windows_msi_recipes TO rmm_app;
CREATE TRIGGER immutable_content BEFORE UPDATE OR DELETE ON windows_msi_recipes
FOR EACH ROW EXECUTE FUNCTION immutable_plan();