36 lines
1.4 KiB
SQL
36 lines
1.4 KiB
SQL
-- Phase 06 / F-001 — Explicit per-tenant capability consent.
|
|
--
|
|
-- One row per (tenantId, pluginId, capabilityName) — the operator's
|
|
-- approval that this plugin may invoke this capability for this tenant.
|
|
-- The lifecycle service refuses to flip Plugin.enabled to true until
|
|
-- every manifest-declared capability has a matching row.
|
|
--
|
|
-- `scopeJson` is the operator-approved scope; null means "use the
|
|
-- manifest-declared scope verbatim".
|
|
|
|
CREATE TABLE "TenantPluginCapabilityGrant" (
|
|
"id" TEXT NOT NULL,
|
|
"tenantId" TEXT NOT NULL,
|
|
"pluginId" TEXT NOT NULL,
|
|
"capabilityName" TEXT NOT NULL,
|
|
"scopeJson" JSONB,
|
|
"grantedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
"grantedByUserId" TEXT,
|
|
CONSTRAINT "TenantPluginCapabilityGrant_pkey" PRIMARY KEY ("id")
|
|
);
|
|
|
|
CREATE UNIQUE INDEX "TenantPluginCapabilityGrant_tenant_plugin_cap_key"
|
|
ON "TenantPluginCapabilityGrant" ("tenantId", "pluginId", "capabilityName");
|
|
|
|
CREATE INDEX "TenantPluginCapabilityGrant_tenant_plugin_idx"
|
|
ON "TenantPluginCapabilityGrant" ("tenantId", "pluginId");
|
|
|
|
-- FK to Plugin via (tenantId, pluginId) — matches the Plugin model's
|
|
-- @@unique constraint, not the Plugin primary key.
|
|
ALTER TABLE "TenantPluginCapabilityGrant"
|
|
ADD CONSTRAINT "TenantPluginCapabilityGrant_plugin_fkey"
|
|
FOREIGN KEY ("pluginId", "tenantId")
|
|
REFERENCES "Plugin"("pluginId", "tenantId")
|
|
ON DELETE CASCADE
|
|
ON UPDATE CASCADE;
|