feat(schedule-tasks): support auto-publish via media accounts

Replace the legacy target_platform string on schedule tasks with a
workspace-aware auto-publish payload (auto_publish + publish_account_ids
JSONB + cover_asset_url + cover_image_asset_id) and migrate the schema,
sqlc queries, generated models, domain struct, ScheduleTaskService DTOs,
and dispatch worker to round-trip the new fields. PromptRuleGeneration
gains a WithPublishJobService hook so executeGeneration can enqueue an
auto-publish job once the article is ready, and worker-generate wires
the publish-job service in. On the admin-web side, extract
PublishArticleModal's account-card builders into a shared
publish-account-cards module, rebuild GenerateTaskDrawer's schedule
mode around account selection plus a CoverPickerModal, and surface the
new "auto publish" column on ScheduleTaskTab. Shared types and i18n
strings cover the new fields.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-30 01:32:19 +08:00
parent c9267d2fae
commit 6e6e19cccb
22 changed files with 1380 additions and 603 deletions
@@ -5,7 +5,6 @@ CREATE TABLE schedule_tasks (
brand_id BIGINT REFERENCES brands(id),
name VARCHAR(100) NOT NULL,
cron_expr VARCHAR(100) NOT NULL,
target_platform VARCHAR(50),
start_at TIMESTAMPTZ,
end_at TIMESTAMPTZ,
next_run_at TIMESTAMPTZ,
@@ -7,10 +7,3 @@ ALTER TABLE schedule_tasks
DROP COLUMN IF EXISTS generate_count,
DROP COLUMN IF EXISTS enable_web_search,
DROP COLUMN IF EXISTS operator_id;
ALTER TABLE schedule_tasks
ALTER COLUMN target_platform TYPE VARCHAR(50)
USING CASE
WHEN target_platform IS NULL THEN NULL
ELSE LEFT(target_platform, 50)
END;
@@ -1,6 +1,3 @@
ALTER TABLE schedule_tasks
ALTER COLUMN target_platform TYPE TEXT;
ALTER TABLE schedule_tasks
ADD COLUMN operator_id BIGINT REFERENCES users(id),
ADD COLUMN enable_web_search BOOLEAN NOT NULL DEFAULT FALSE,
@@ -0,0 +1,11 @@
DROP INDEX IF EXISTS idx_schedule_task_workspace;
ALTER TABLE schedule_tasks
DROP CONSTRAINT IF EXISTS chk_schedule_tasks_publish_account_ids_json;
ALTER TABLE schedule_tasks
DROP COLUMN IF EXISTS cover_image_asset_id,
DROP COLUMN IF EXISTS cover_asset_url,
DROP COLUMN IF EXISTS publish_account_ids,
DROP COLUMN IF EXISTS auto_publish,
DROP COLUMN IF EXISTS workspace_id;
@@ -0,0 +1,14 @@
ALTER TABLE schedule_tasks
ADD COLUMN workspace_id BIGINT REFERENCES workspaces(id),
ADD COLUMN auto_publish BOOLEAN NOT NULL DEFAULT FALSE,
ADD COLUMN publish_account_ids JSONB NOT NULL DEFAULT '[]'::jsonb,
ADD COLUMN cover_asset_url TEXT,
ADD COLUMN cover_image_asset_id BIGINT;
ALTER TABLE schedule_tasks
ADD CONSTRAINT chk_schedule_tasks_publish_account_ids_json
CHECK (jsonb_typeof(publish_account_ids) = 'array');
CREATE INDEX idx_schedule_task_workspace
ON schedule_tasks(tenant_id, workspace_id, created_at DESC)
WHERE deleted_at IS NULL;