Files
geo/server/migrations/20260421100020_create_desktop_tasks.up.sql
T
root a617d39a4a feat(desktop): drop parked review flow, add publish management
SaaS 侧人工审核后才创建 publish job,desktop 不再做二次审核:移除
manual/waiting_user/parked/from_parked 状态机与 LeaseFromParked 查询,
desktop client 只执行发布并新增"发布管理"页(待发布队列 / 历史 / 再次
发送)。同时抽离 @geo/publisher-platforms 共享适配器包、新增 Redis-based
desktop_presence 与 publish_record_support,刷新 admin-web 发布弹窗与
媒体库;plan A / spec 文档同步口径。
2026-04-20 09:52:48 +08:00

82 lines
2.9 KiB
SQL

CREATE EXTENSION IF NOT EXISTS pgcrypto;
CREATE TABLE IF NOT EXISTS desktop_publish_jobs (
id BIGSERIAL PRIMARY KEY,
desktop_id UUID NOT NULL DEFAULT gen_random_uuid(),
tenant_id BIGINT NOT NULL REFERENCES tenants(id),
workspace_id BIGINT NOT NULL REFERENCES workspaces(id),
created_by_user_id BIGINT NOT NULL REFERENCES users(id),
title TEXT NOT NULL,
content_ref JSONB NOT NULL,
scheduled_at TIMESTAMPTZ,
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
UNIQUE (desktop_id)
);
CREATE INDEX IF NOT EXISTS idx_desktop_publish_jobs_workspace_created
ON desktop_publish_jobs (workspace_id, created_at DESC);
CREATE TABLE IF NOT EXISTS desktop_tasks (
id BIGSERIAL PRIMARY KEY,
desktop_id UUID NOT NULL DEFAULT gen_random_uuid(),
job_id UUID NOT NULL,
tenant_id BIGINT NOT NULL REFERENCES tenants(id),
workspace_id BIGINT NOT NULL REFERENCES workspaces(id),
target_account_id UUID NOT NULL REFERENCES platform_accounts(desktop_id),
target_client_id UUID NOT NULL REFERENCES desktop_clients(id),
platform_id VARCHAR(64) NOT NULL REFERENCES media_platforms(platform_id),
kind TEXT NOT NULL,
payload JSONB NOT NULL,
status TEXT NOT NULL,
dedup_key TEXT,
active_attempt_id UUID,
lease_token_hash BYTEA,
lease_expires_at TIMESTAMPTZ,
attempts INT NOT NULL DEFAULT 0,
result JSONB,
error JSONB,
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
UNIQUE (desktop_id)
);
CREATE INDEX IF NOT EXISTS idx_desktop_tasks_job
ON desktop_tasks (job_id);
CREATE INDEX IF NOT EXISTS idx_desktop_tasks_target_client_status
ON desktop_tasks (target_client_id, status)
WHERE status IN ('queued', 'in_progress');
CREATE INDEX IF NOT EXISTS idx_desktop_tasks_workspace_status_created
ON desktop_tasks (workspace_id, status, created_at DESC);
CREATE INDEX IF NOT EXISTS idx_desktop_tasks_target_account
ON desktop_tasks (target_account_id);
CREATE TABLE IF NOT EXISTS desktop_task_attempts (
id BIGSERIAL PRIMARY KEY,
desktop_id UUID NOT NULL DEFAULT gen_random_uuid(),
task_id UUID NOT NULL REFERENCES desktop_tasks(desktop_id) ON DELETE CASCADE,
client_id UUID NOT NULL REFERENCES desktop_clients(id),
lease_token_hash BYTEA,
started_at TIMESTAMPTZ NOT NULL DEFAULT now(),
ended_at TIMESTAMPTZ,
final_status TEXT,
error JSONB,
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
UNIQUE (desktop_id)
);
CREATE INDEX IF NOT EXISTS idx_desktop_task_attempts_task_started
ON desktop_task_attempts (task_id, started_at DESC);
CREATE TABLE IF NOT EXISTS desktop_task_traces (
task_id UUID NOT NULL REFERENCES desktop_tasks(desktop_id) ON DELETE CASCADE,
attempt_id UUID,
size BIGINT,
uploaded_at TIMESTAMPTZ,
object_key TEXT,
PRIMARY KEY (task_id, attempt_id)
);