A package is now a set of immutable versions with declared grants and a default version that installations run unless they pin another. Adopting a version is what accepts its grants, replacing the per-extension lifecycle actions with version, pin and update-policy commands.
83 lines
3.6 KiB
SQL
83 lines
3.6 KiB
SQL
-- +goose Up
|
|
-- A package version is one release of a package: its binary, the digest it
|
|
-- must hash to, the grants and settings it declared, and the grants the
|
|
-- instance accepted for it, null until accepted. A version accepted by path is
|
|
-- accepted when it is stored, and its installations carry the grants the
|
|
-- administrator gave them. A version is immutable: the
|
|
-- same version with a different digest is refused. capabilities and effects
|
|
-- are what the version declared when it last loaded.
|
|
CREATE TABLE connectors.package_versions (
|
|
id uuid PRIMARY KEY,
|
|
package_id uuid NOT NULL REFERENCES connectors.packages (id) ON DELETE CASCADE,
|
|
version text NOT NULL,
|
|
path text NOT NULL,
|
|
sha256 text NOT NULL,
|
|
declared jsonb NOT NULL DEFAULT '{}',
|
|
settings jsonb NOT NULL DEFAULT '[]',
|
|
accepted jsonb,
|
|
accepted_by_id text NOT NULL DEFAULT '',
|
|
capabilities jsonb,
|
|
effects jsonb,
|
|
created_at timestamptz NOT NULL DEFAULT now(),
|
|
UNIQUE (package_id, version)
|
|
);
|
|
|
|
-- A package's default version is what its installations run unless one pins
|
|
-- another. managed says the package came from the catalogue.
|
|
ALTER TABLE connectors.packages
|
|
ADD COLUMN display_name text NOT NULL DEFAULT '',
|
|
ADD COLUMN description text NOT NULL DEFAULT '',
|
|
ADD COLUMN managed boolean NOT NULL DEFAULT false,
|
|
ADD COLUMN update_policy text NOT NULL DEFAULT 'manual' CHECK (update_policy IN ('manual', 'auto')),
|
|
ADD COLUMN default_version_id uuid REFERENCES connectors.package_versions (id);
|
|
|
|
INSERT INTO connectors.package_versions
|
|
(id, package_id, version, path, sha256, declared, accepted, accepted_by_id, capabilities, effects)
|
|
SELECT gen_random_uuid(), p.id,
|
|
COALESCE(p.manifest #>> '{state,current,version}', 'local-' || left(p.sha256, 12)),
|
|
p.path, p.sha256,
|
|
COALESCE(p.manifest #> '{state,current,declared}', '{}'),
|
|
CASE WHEN p.manifest IS NULL THEN '{}'::jsonb ELSE p.manifest #> '{state,accepted}' END,
|
|
p.accepted_by_id, p.capabilities, p.effects
|
|
FROM connectors.packages p;
|
|
|
|
UPDATE connectors.packages p
|
|
SET default_version_id = v.id,
|
|
managed = p.manifest IS NOT NULL,
|
|
display_name = COALESCE(p.manifest ->> 'display_name', ''),
|
|
description = COALESCE(p.manifest ->> 'description', ''),
|
|
update_policy = COALESCE(p.manifest #>> '{state,policy}', 'manual')
|
|
FROM connectors.package_versions v
|
|
WHERE v.package_id = p.id;
|
|
|
|
ALTER TABLE connectors.packages
|
|
DROP COLUMN path,
|
|
DROP COLUMN sha256,
|
|
DROP COLUMN manifest,
|
|
DROP COLUMN capabilities,
|
|
DROP COLUMN effects;
|
|
|
|
-- An installation runs its package's default version unless it pins one.
|
|
ALTER TABLE connectors.installations
|
|
ADD COLUMN package_version_id uuid REFERENCES connectors.package_versions (id) ON DELETE RESTRICT;
|
|
|
|
-- +goose Down
|
|
ALTER TABLE connectors.installations DROP COLUMN package_version_id;
|
|
ALTER TABLE connectors.packages
|
|
ADD COLUMN path text NOT NULL DEFAULT '',
|
|
ADD COLUMN sha256 text NOT NULL DEFAULT '',
|
|
ADD COLUMN manifest jsonb,
|
|
ADD COLUMN capabilities jsonb,
|
|
ADD COLUMN effects jsonb;
|
|
UPDATE connectors.packages p
|
|
SET path = v.path, sha256 = v.sha256, capabilities = v.capabilities, effects = v.effects
|
|
FROM connectors.package_versions v
|
|
WHERE v.id = p.default_version_id;
|
|
ALTER TABLE connectors.packages
|
|
DROP COLUMN default_version_id,
|
|
DROP COLUMN update_policy,
|
|
DROP COLUMN managed,
|
|
DROP COLUMN description,
|
|
DROP COLUMN display_name;
|
|
DROP TABLE connectors.package_versions;
|