6e6e19cccb
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>
68 lines
3.4 KiB
SQL
68 lines
3.4 KiB
SQL
-- name: ListScheduleTasks :many
|
|
SELECT st.id, st.tenant_id, st.workspace_id, st.prompt_rule_id, st.brand_id, st.name,
|
|
st.cron_expr, st.auto_publish, st.publish_account_ids, st.cover_asset_url, st.cover_image_asset_id,
|
|
st.start_at, st.end_at,
|
|
st.next_run_at, st.status, st.created_at, st.updated_at,
|
|
pr.name AS prompt_rule_name,
|
|
b.name AS brand_name
|
|
FROM schedule_tasks st
|
|
LEFT JOIN prompt_rules pr ON pr.id = st.prompt_rule_id
|
|
LEFT JOIN brands b ON b.id = st.brand_id
|
|
WHERE st.tenant_id = sqlc.arg(tenant_id)
|
|
AND st.deleted_at IS NULL
|
|
AND (sqlc.narg(status)::text IS NULL OR st.status = sqlc.narg(status))
|
|
AND (sqlc.narg(prompt_rule_id)::bigint IS NULL OR st.prompt_rule_id = sqlc.narg(prompt_rule_id))
|
|
ORDER BY st.created_at DESC
|
|
LIMIT sqlc.arg(page_size) OFFSET sqlc.arg(page_offset);
|
|
|
|
-- name: CountScheduleTasks :one
|
|
SELECT COUNT(*)
|
|
FROM schedule_tasks
|
|
WHERE tenant_id = sqlc.arg(tenant_id)
|
|
AND deleted_at IS NULL
|
|
AND (sqlc.narg(status)::text IS NULL OR status = sqlc.narg(status))
|
|
AND (sqlc.narg(prompt_rule_id)::bigint IS NULL OR prompt_rule_id = sqlc.narg(prompt_rule_id));
|
|
|
|
-- name: GetScheduleTaskByID :one
|
|
SELECT st.id, st.tenant_id, st.workspace_id, st.prompt_rule_id, st.brand_id, st.name,
|
|
st.cron_expr, st.auto_publish, st.publish_account_ids, st.cover_asset_url, st.cover_image_asset_id,
|
|
st.start_at, st.end_at,
|
|
st.next_run_at, st.status, st.created_at, st.updated_at,
|
|
pr.name AS prompt_rule_name,
|
|
b.name AS brand_name
|
|
FROM schedule_tasks st
|
|
LEFT JOIN prompt_rules pr ON pr.id = st.prompt_rule_id
|
|
LEFT JOIN brands b ON b.id = st.brand_id
|
|
WHERE st.id = sqlc.arg(id) AND st.tenant_id = sqlc.arg(tenant_id) AND st.deleted_at IS NULL;
|
|
|
|
-- name: CreateScheduleTask :one
|
|
INSERT INTO schedule_tasks (tenant_id, workspace_id, prompt_rule_id, brand_id, name, cron_expr,
|
|
auto_publish, publish_account_ids, cover_asset_url, cover_image_asset_id,
|
|
start_at, end_at, next_run_at)
|
|
VALUES (sqlc.arg(tenant_id), sqlc.narg(workspace_id), sqlc.arg(prompt_rule_id), sqlc.narg(brand_id), sqlc.arg(name),
|
|
sqlc.arg(cron_expr), sqlc.arg(auto_publish), sqlc.arg(publish_account_ids), sqlc.narg(cover_asset_url),
|
|
sqlc.narg(cover_image_asset_id), sqlc.narg(start_at), sqlc.narg(end_at),
|
|
sqlc.narg(next_run_at))
|
|
RETURNING id, created_at;
|
|
|
|
-- name: UpdateScheduleTask :exec
|
|
UPDATE schedule_tasks
|
|
SET prompt_rule_id = sqlc.arg(prompt_rule_id), brand_id = sqlc.narg(brand_id),
|
|
name = sqlc.arg(name), cron_expr = sqlc.arg(cron_expr),
|
|
workspace_id = sqlc.narg(workspace_id),
|
|
auto_publish = sqlc.arg(auto_publish),
|
|
publish_account_ids = sqlc.arg(publish_account_ids),
|
|
cover_asset_url = sqlc.narg(cover_asset_url),
|
|
cover_image_asset_id = sqlc.narg(cover_image_asset_id),
|
|
start_at = sqlc.narg(start_at), end_at = sqlc.narg(end_at),
|
|
next_run_at = sqlc.narg(next_run_at), updated_at = NOW()
|
|
WHERE id = sqlc.arg(id) AND tenant_id = sqlc.arg(tenant_id) AND deleted_at IS NULL;
|
|
|
|
-- name: UpdateScheduleTaskStatus :exec
|
|
UPDATE schedule_tasks SET status = sqlc.arg(status), updated_at = NOW()
|
|
WHERE id = sqlc.arg(id) AND tenant_id = sqlc.arg(tenant_id) AND deleted_at IS NULL;
|
|
|
|
-- name: SoftDeleteScheduleTask :exec
|
|
UPDATE schedule_tasks SET deleted_at = NOW(), updated_at = NOW()
|
|
WHERE id = sqlc.arg(id) AND tenant_id = sqlc.arg(tenant_id) AND deleted_at IS NULL;
|