feat: add brand asset cleanup worker and related functionality
Frontend CI / Frontend (push) Successful in 3m23s
Backend CI / Backend (push) Failing after 6m46s

- Implemented a new BrandAssetCleanupWorker to handle the cleanup of brand-related assets after a brand is deleted.
- Added SQL queries for cleaning up articles, keywords, questions, competitors, and monitoring data associated with a brand.
- Introduced a new API endpoint to delete publish records.
- Updated the router to include the new delete publish record endpoint.
- Added tests for the BrandAssetCleanupWorker to ensure proper functionality.
- Created migration scripts to support soft deletion of publish records and to add the brand asset cleanup scheduler job.
This commit is contained in:
2026-06-19 11:45:13 +08:00
parent 97ae601cfd
commit 6e0519a232
29 changed files with 1621 additions and 54 deletions
@@ -169,6 +169,26 @@ WHERE desktop_id = sqlc.arg(desktop_id)
AND status = 'queued'
RETURNING *;
-- name: CancelQueuedPublishDesktopTaskByOwner :one
UPDATE desktop_tasks AS t
SET status = 'aborted',
error = sqlc.narg(error),
active_attempt_id = NULL,
lease_token_hash = NULL,
lease_expires_at = NULL,
updated_at = now()
FROM desktop_publish_jobs AS j
WHERE t.desktop_id = sqlc.arg(desktop_id)
AND t.tenant_id = sqlc.arg(tenant_id)
AND t.workspace_id = sqlc.arg(workspace_id)
AND t.kind = 'publish'
AND t.status = 'queued'
AND j.desktop_id = t.job_id
AND j.tenant_id = t.tenant_id
AND j.workspace_id = t.workspace_id
AND j.created_by_user_id = sqlc.arg(user_id)
RETURNING t.*;
-- name: TenantCancelDesktopTask :one
UPDATE desktop_tasks
SET status = 'aborted',
@@ -178,8 +198,17 @@ SET status = 'aborted',
lease_expires_at = NULL,
updated_at = now()
WHERE desktop_id = sqlc.arg(desktop_id)
AND tenant_id = sqlc.arg(tenant_id)
AND workspace_id = sqlc.arg(workspace_id)
AND status = 'queued'
AND EXISTS (
SELECT 1
FROM desktop_publish_jobs AS j
WHERE j.desktop_id = desktop_tasks.job_id
AND j.tenant_id = desktop_tasks.tenant_id
AND j.workspace_id = desktop_tasks.workspace_id
AND j.created_by_user_id = sqlc.arg(user_id)
)
RETURNING *;
-- name: ReconcileDesktopTask :one