From 61b91c473b62a60fa29bcd24e2c94d26958798f1 Mon Sep 17 00:00:00 2001 From: Krispire Admin Date: Wed, 3 Jun 2026 14:51:59 +0530 Subject: [PATCH] feat: post reshare enhancements --- ...backfill_reshare_inherited_images.down.sql | 5 ++++ ...6_backfill_reshare_inherited_images.up.sql | 29 +++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 migrations/0016_backfill_reshare_inherited_images.down.sql create mode 100644 migrations/0016_backfill_reshare_inherited_images.up.sql diff --git a/migrations/0016_backfill_reshare_inherited_images.down.sql b/migrations/0016_backfill_reshare_inherited_images.down.sql new file mode 100644 index 0000000..aa4ea17 --- /dev/null +++ b/migrations/0016_backfill_reshare_inherited_images.down.sql @@ -0,0 +1,5 @@ +-- This is a data-only backfill — there's no clean rollback because we +-- can't distinguish post_images rows added by this migration from rows +-- the resharer added afterwards. Intentional no-op; documented for the +-- runbook only. +SELECT 1; diff --git a/migrations/0016_backfill_reshare_inherited_images.up.sql b/migrations/0016_backfill_reshare_inherited_images.up.sql new file mode 100644 index 0000000..f24d688 --- /dev/null +++ b/migrations/0016_backfill_reshare_inherited_images.up.sql @@ -0,0 +1,29 @@ +-- Backfill the "reshares inherit the canonical's images" rule for any +-- reshare row that landed in `posts` without an image set. +-- +-- Two paths created such rows: +-- +-- 1. Reshares made BEFORE migration 0014 had no per-resharer image +-- table to snapshot into, so when 0015 collapsed the old +-- post_reshares model into real posts rows there was nothing for +-- it to copy — those reshares now show with a blank background +-- where the original author has a cover image. +-- +-- 2. Any future code path that creates a reshare row but forgets to +-- copy the images. Defensive — current `Reshare` in +-- internal/repository/post_repo.go does copy, but this migration +-- makes the database self-healing if we ever regress. +-- +-- The copy is scoped to reshares with ZERO images of their own so we +-- never overwrite a resharer's explicit customization (including an +-- explicit "no background" — though that path didn't exist at the time +-- the affected rows were created, the guard keeps us safe for any +-- future re-runs of equivalent backfills). +INSERT INTO post_images (post_id, url, position) +SELECT r.id, i.url, i.position +FROM posts r +JOIN post_images i ON i.post_id = r.reshared_from_post_id +WHERE r.reshared_from_post_id IS NOT NULL + AND NOT EXISTS ( + SELECT 1 FROM post_images WHERE post_id = r.id + );