100 lines
4.7 KiB
SQL
100 lines
4.7 KiB
SQL
-- +goose Up
|
|
CREATE SCHEMA connectors;
|
|
|
|
-- A package is an extension the instance has accepted: its name, contract,
|
|
-- binary and digest, and the manifest that declares its settings, capabilities
|
|
-- and effects. name is the immutable package identifier from the catalogue or
|
|
-- acceptance request: a package is never renamed, and a name is never given to
|
|
-- a different package. It holds no configuration and no credentials, so it is
|
|
-- accepted once for the whole instance and configured by its installations.
|
|
CREATE TABLE connectors.packages (
|
|
id uuid PRIMARY KEY,
|
|
name text NOT NULL UNIQUE,
|
|
contract text NOT NULL CHECK (contract IN ('connector', 'secretengine', 'mcp', 'guard')),
|
|
path text NOT NULL,
|
|
sha256 text NOT NULL,
|
|
manifest jsonb,
|
|
capabilities jsonb,
|
|
effects jsonb,
|
|
accepted_by_id text NOT NULL,
|
|
accepted_at timestamptz NOT NULL DEFAULT now(),
|
|
updated_at timestamptz NOT NULL DEFAULT now()
|
|
);
|
|
|
|
-- An installation is one configuration of a package, owned by a scope: the
|
|
-- instance, one organisation or one person. A binding names an installation or
|
|
-- inherits one, resolving the person's first, then the organisation's, then the
|
|
-- instance's. name is unique within its scope, so the same name can resolve to
|
|
-- a different installation for each organisation or person. tools lists the
|
|
-- tools an MCP server reported.
|
|
CREATE TABLE connectors.installations (
|
|
id uuid PRIMARY KEY,
|
|
package_id uuid NOT NULL REFERENCES connectors.packages (id) ON DELETE RESTRICT,
|
|
scope text NOT NULL CHECK (scope IN ('instance', 'org', 'person')),
|
|
org_id text NOT NULL DEFAULT '',
|
|
person_id text NOT NULL DEFAULT '',
|
|
name text NOT NULL,
|
|
settings jsonb NOT NULL DEFAULT '{}',
|
|
egress jsonb NOT NULL DEFAULT '[]',
|
|
env jsonb NOT NULL DEFAULT '[]',
|
|
credentials jsonb NOT NULL DEFAULT '{}',
|
|
args jsonb NOT NULL DEFAULT '[]',
|
|
url text NOT NULL DEFAULT '',
|
|
tools jsonb NOT NULL DEFAULT '[]',
|
|
enabled boolean NOT NULL DEFAULT true,
|
|
created_at timestamptz NOT NULL DEFAULT now(),
|
|
updated_at timestamptz NOT NULL DEFAULT now(),
|
|
UNIQUE (scope, org_id, person_id, name),
|
|
CHECK ((scope <> 'instance') OR ((org_id = '') AND (person_id = ''))),
|
|
CHECK ((scope <> 'org') OR ((org_id <> '') AND (person_id = ''))),
|
|
CHECK ((scope <> 'person') OR ((org_id = '') AND (person_id <> '')))
|
|
);
|
|
CREATE INDEX installations_by_package ON connectors.installations (package_id);
|
|
|
|
-- An organisation or a person can switch off an installation it would
|
|
-- otherwise inherit from a broader scope.
|
|
CREATE TABLE connectors.installation_overrides (
|
|
installation_id uuid NOT NULL REFERENCES connectors.installations (id) ON DELETE CASCADE,
|
|
scope text NOT NULL CHECK (scope IN ('org', 'person')),
|
|
org_id text NOT NULL DEFAULT '',
|
|
person_id text NOT NULL DEFAULT '',
|
|
disabled_by_id text NOT NULL,
|
|
disabled_at timestamptz NOT NULL DEFAULT now(),
|
|
PRIMARY KEY (installation_id, scope, org_id, person_id),
|
|
CHECK ((scope <> 'org') OR ((org_id <> '') AND (person_id = ''))),
|
|
CHECK ((scope <> 'person') OR ((org_id = '') AND (person_id <> '')))
|
|
);
|
|
|
|
-- A credential's fields are sealed with age. Each field holds a value or the
|
|
-- secret engine key the value is read from. A credential is owned by a scope
|
|
-- and resolved like an installation.
|
|
CREATE TABLE connectors.credentials (
|
|
id uuid PRIMARY KEY,
|
|
scope text NOT NULL CHECK (scope IN ('instance', 'org', 'person')),
|
|
org_id text NOT NULL DEFAULT '',
|
|
person_id text NOT NULL DEFAULT '',
|
|
name text NOT NULL,
|
|
kind text NOT NULL CHECK (kind IN ('machine', 'age', 'basic', 'bearer')),
|
|
sealed bytea NOT NULL,
|
|
updated_at timestamptz NOT NULL DEFAULT now(),
|
|
UNIQUE (scope, org_id, person_id, name),
|
|
CHECK ((scope <> 'instance') OR ((org_id = '') AND (person_id = ''))),
|
|
CHECK ((scope <> 'org') OR ((org_id <> '') AND (person_id = ''))),
|
|
CHECK ((scope <> 'person') OR ((org_id = '') AND (person_id <> '')))
|
|
);
|
|
|
|
-- The location of the instance's extension catalogue and the public key that
|
|
-- verifies its signature. newest_issued_at is the issue time of the newest
|
|
-- catalogue accepted from it, so an older catalogue replayed by the source or
|
|
-- the network is refused.
|
|
CREATE TABLE connectors.catalogue_source (
|
|
singleton boolean DEFAULT true PRIMARY KEY CHECK (singleton),
|
|
location text NOT NULL,
|
|
public_key text NOT NULL,
|
|
newest_issued_at timestamptz,
|
|
updated_at timestamptz NOT NULL DEFAULT now()
|
|
);
|
|
|
|
-- +goose Down
|
|
DROP SCHEMA connectors CASCADE;
|