Files
uptimesebi/internal/migrations/sql/00032_agent_instances.sql

25 lines
1.1 KiB
SQL

-- +goose Up
-- Processes running with an agent token. Several may share a token; check
-- results name the instance that ran them.
CREATE TABLE agent_instances (
id uuid PRIMARY KEY,
agent_id uuid NOT NULL REFERENCES agents (id) ON DELETE CASCADE,
org_id uuid REFERENCES orgs (id) ON DELETE CASCADE,
release text NOT NULL DEFAULT '',
started_at timestamptz NOT NULL DEFAULT now(),
last_seen_at timestamptz NOT NULL DEFAULT now()
);
CREATE INDEX agent_instances_agent_idx ON agent_instances (agent_id, last_seen_at DESC);
ALTER TABLE agent_instances ENABLE ROW LEVEL SECURITY;
ALTER TABLE agent_instances FORCE ROW LEVEL SECURITY;
-- Platform instances serve every organization and are visible to all, like
-- platform regions.
CREATE POLICY agent_instances_read ON agent_instances FOR SELECT
USING (app_scope_system() OR org_id IS NULL OR org_id = app_org_id());
CREATE POLICY agent_instances_write ON agent_instances FOR ALL
USING (app_scope_system()) WITH CHECK (app_scope_system());
-- +goose Down
DROP TABLE agent_instances;