A trigger function that save only the final recipient for zora_media …#180
Conversation
…tokens within in_process_transfers.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Updates to Preview Branch (techengme/myc-4640-a-trigger-function-that-save-only-the-final-recipient-for) ↗︎
Tasks are run on every commit but only new migration files are pushed.
View logs for this Workflow Run ↗︎. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds a PostgreSQL migration that creates (replaces) a trigger function and trigger on Changes
Sequence Diagram(s)sequenceDiagram
participant Inserter as Client/Inserter
participant Transfers as in_process_transfers
participant Trigger as set_zora_media_token_latest_holder_on_insert()
participant Moments as in_process_moments
participant Collections as in_process_collections
Inserter->>Transfers: INSERT new transfer (NEW)
Transfers->>Trigger: AFTER INSERT FOR EACH ROW (NEW)
Trigger->>Moments: SELECT moment JOIN collection WHERE moment = NEW.moment
Moments->>Collections: check collection.protocol = 'zora_media'
alt not zora_media
Trigger-->>Transfers: RETURN NEW (no-op)
else is zora_media
Trigger->>Transfers: SELECT newer transfer rows for same moment
alt newer exists
Trigger-->>Transfers: RETURN NEW (no-op)
else
Trigger->>Transfers: DELETE other rows for same moment with transferred_at <= NEW.transferred_at AND id <> NEW.id
Trigger-->>Transfers: RETURN NEW
end
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/lib/supabase/migrations/20260418100005_add_zora_media_transfer_dedup_trigger.sql (1)
29-32: Consider seeding existing zora_media transfers.This trigger only dedups on future inserts; any zora_media moments that already have multiple transfer rows at deploy time will remain un-deduplicated until a new transfer arrives. If that's intentional, ignore; otherwise consider a one-time cleanup statement in this migration keeping only the row with the greatest
transferred_atper zora_mediamoment.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/lib/supabase/migrations/20260418100005_add_zora_media_transfer_dedup_trigger.sql` around lines 29 - 32, Add a one-time cleanup in this migration to dedupe existing rows before creating the trigger: for table public.in_process_transfers, delete any rows per zora_media moment that are not the latest by transferred_at (i.e., keep only the row with the max(transferred_at) for each zora_media moment identifier) then create the trigger zora_media_token_latest_holder_trigger that executes public.set_zora_media_token_latest_holder_on_insert(); ensure you reference the actual zora_media moment identifier column in the DELETE (e.g., moment_id or zora_media_moment_id) and use transferred_at to select the latest row.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In
`@src/lib/supabase/migrations/20260418100005_add_zora_media_transfer_dedup_trigger.sql`:
- Around line 8-21: The trigger currently assumes NEW is the latest transfer and
deletes other rows indiscriminately; instead, ensure dedup only removes rows
older than NEW and no-ops when a strictly newer transfer exists. Update the
trigger/function that runs on INSERT into in_process_transfers: first check for
any existing row with same moment and transferred_at > NEW.transferred_at (or
equal and higher precedence if needed) and RETURN NEW without deleting if such a
newer row exists; otherwise DELETE FROM in_process_transfers WHERE moment =
NEW.moment AND id <> NEW.id AND transferred_at <= NEW.transferred_at so you only
remove older or equal-timestamped rows. Reference symbols: in_process_transfers,
in_process_moments, in_process_collections, NEW.transferred_at, NEW.moment,
NEW.id.
---
Nitpick comments:
In
`@src/lib/supabase/migrations/20260418100005_add_zora_media_transfer_dedup_trigger.sql`:
- Around line 29-32: Add a one-time cleanup in this migration to dedupe existing
rows before creating the trigger: for table public.in_process_transfers, delete
any rows per zora_media moment that are not the latest by transferred_at (i.e.,
keep only the row with the max(transferred_at) for each zora_media moment
identifier) then create the trigger zora_media_token_latest_holder_trigger that
executes public.set_zora_media_token_latest_holder_on_insert(); ensure you
reference the actual zora_media moment identifier column in the DELETE (e.g.,
moment_id or zora_media_moment_id) and use transferred_at to select the latest
row.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 5a654ba8-ca24-4233-b8ae-69ce51d4f32c
📒 Files selected for processing (1)
src/lib/supabase/migrations/20260418100005_add_zora_media_transfer_dedup_trigger.sql
…tokens within in_process_transfers.
Summary by CodeRabbit