24 lines
1.3 KiB
PL/PgSQL
24 lines
1.3 KiB
PL/PgSQL
BEGIN;
|
|
CREATE TABLE canvas_documents (
|
|
id uuid PRIMARY KEY, owner_id uuid NOT NULL REFERENCES account_users(id) ON DELETE CASCADE,
|
|
name text NOT NULL DEFAULT '未命名画布' CHECK(length(name) BETWEEN 1 AND 200),
|
|
revision integer NOT NULL DEFAULT 1 CHECK(revision>0), document_key text NOT NULL,
|
|
updated_at timestamptz NOT NULL DEFAULT now()
|
|
);
|
|
CREATE INDEX canvas_owner_updated ON canvas_documents(owner_id,updated_at DESC);
|
|
CREATE TABLE canvas_agent_links (
|
|
digest text PRIMARY KEY, canvas_id uuid NOT NULL REFERENCES canvas_documents(id) ON DELETE CASCADE,
|
|
expires_at timestamptz NOT NULL, last_seen_at timestamptz
|
|
);
|
|
CREATE INDEX canvas_link_expiry ON canvas_agent_links(canvas_id,expires_at);
|
|
CREATE TABLE canvas_tasks (
|
|
id uuid PRIMARY KEY, canvas_id uuid NOT NULL REFERENCES canvas_documents(id) ON DELETE CASCADE,
|
|
target_id text NOT NULL, source_revision integer NOT NULL,
|
|
status text NOT NULL DEFAULT 'queued' CHECK(status IN ('queued','running','succeeded','failed')),
|
|
request_key text NOT NULL, result_digest text, error text,
|
|
created_at timestamptz NOT NULL DEFAULT now(), updated_at timestamptz NOT NULL DEFAULT now()
|
|
);
|
|
CREATE UNIQUE INDEX canvas_target_active_task ON canvas_tasks(canvas_id,target_id) WHERE status IN ('queued','running');
|
|
INSERT INTO schema_migrations(version) VALUES ('016_canvas_workspace');
|
|
COMMIT;
|