Improve raw rewrite flow and publication status sync
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
UPDATE raw_posts rp
|
||||
SET publication_status='published',
|
||||
editorial_status='published',
|
||||
publication_error=NULL,
|
||||
published_at=COALESCE(rp.published_at, pp.published_at, NOW()),
|
||||
updated_at=NOW()
|
||||
FROM (
|
||||
SELECT raw_post_id, MIN(published_at) AS published_at
|
||||
FROM post_publications
|
||||
WHERE status='published'
|
||||
GROUP BY raw_post_id
|
||||
) pp
|
||||
WHERE rp.id=pp.raw_post_id
|
||||
AND COALESCE(rp.editorial_status, 'review') IN ('accepted', 'publish_failed');
|
||||
|
||||
UPDATE raw_posts rp
|
||||
SET publication_status='publish_failed',
|
||||
editorial_status='publish_failed',
|
||||
publication_error=COALESCE(pp.error, rp.publication_error),
|
||||
updated_at=NOW()
|
||||
FROM (
|
||||
SELECT DISTINCT ON (raw_post_id) raw_post_id, error
|
||||
FROM post_publications
|
||||
WHERE status='publish_failed'
|
||||
ORDER BY raw_post_id, updated_at DESC NULLS LAST, id DESC
|
||||
) pp
|
||||
WHERE rp.id=pp.raw_post_id
|
||||
AND COALESCE(rp.editorial_status, 'review')='accepted'
|
||||
AND NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM post_publications ok
|
||||
WHERE ok.raw_post_id=rp.id AND ok.status='published'
|
||||
);
|
||||
Reference in New Issue
Block a user