Skip to content

A trigger function that save only the final recipient for zora_media …#180

Merged
techeng322 merged 2 commits intomainfrom
techengme/myc-4640-a-trigger-function-that-save-only-the-final-recipient-for
Apr 17, 2026
Merged

A trigger function that save only the final recipient for zora_media …#180
techeng322 merged 2 commits intomainfrom
techengme/myc-4640-a-trigger-function-that-save-only-the-final-recipient-for

Conversation

@techeng322
Copy link
Copy Markdown
Collaborator

@techeng322 techeng322 commented Apr 17, 2026

…tokens within in_process_transfers.

Summary by CodeRabbit

  • Chores
    • Added trigger-driven deduplication for Zora media transfer records on insert.
    • Ensures only the latest transfer entry is retained per item, removing older conflicting transfer rows to keep transfer data consistent.

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 17, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
in-process-api Ready Ready Preview Apr 17, 2026 2:22pm

Request Review

@supabase
Copy link
Copy Markdown

supabase bot commented Apr 17, 2026

Updates to Preview Branch (techengme/myc-4640-a-trigger-function-that-save-only-the-final-recipient-for) ↗︎

Deployments Status Updated
Database Fri, 17 Apr 2026 14:22:15 UTC
Services Fri, 17 Apr 2026 14:22:15 UTC
APIs Fri, 17 Apr 2026 14:22:15 UTC

Tasks are run on every commit but only new migration files are pushed.
Close and reopen this PR if you want to apply changes from existing seed or migration files.

Tasks Status Updated
Configurations Fri, 17 Apr 2026 14:22:15 UTC
Migrations Fri, 17 Apr 2026 14:22:15 UTC
Seeding Fri, 17 Apr 2026 14:22:15 UTC
Edge Functions Fri, 17 Apr 2026 14:22:15 UTC

View logs for this Workflow Run ↗︎.
Learn more about Supabase for Git ↗︎.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 17, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 60a2db2e-cc32-4974-a2fa-d0a7229fe2fc

📥 Commits

Reviewing files that changed from the base of the PR and between d115bf2 and 16218c7.

📒 Files selected for processing (1)
  • src/lib/supabase/migrations/20260418100005_add_zora_media_transfer_dedup_trigger.sql
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/lib/supabase/migrations/20260418100005_add_zora_media_transfer_dedup_trigger.sql

📝 Walkthrough

Walkthrough

Adds a PostgreSQL migration that creates (replaces) a trigger function and trigger on public.in_process_transfers. On insert, the trigger verifies the related moment belongs to a zora_media collection and deduplicates transfer rows for that moment, keeping only the latest according to transferred_at/id ordering.

Changes

Cohort / File(s) Summary
Zora Media Transfer Deduplication Trigger
src/lib/supabase/migrations/20260418100005_add_zora_media_transfer_dedup_trigger.sql
Adds/replaces PL/pgSQL function public.set_zora_media_token_latest_holder_on_insert() and AFTER INSERT FOR EACH ROW trigger zora_media_token_latest_holder_trigger on public.in_process_transfers. Function checks in_process_momentsin_process_collections for protocol = 'zora_media', aborts if not, otherwise deletes older/duplicate transfer rows for the same moment per transferred_at/id ordering.

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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 I hopped into SQL fields so bright,
Sniffed moments, collections, did what’s right,
I nibbled duplicates down to one,
A tidy ledger when insertion’s done,
Hooray — no extra hops tonight! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: adding a trigger function that saves only the final recipient for zora_media tokens, which matches the core functionality of the migration file.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch techengme/myc-4640-a-trigger-function-that-save-only-the-final-recipient-for

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_at per zora_media moment.

🤖 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

📥 Commits

Reviewing files that changed from the base of the PR and between 89e55cb and d115bf2.

📒 Files selected for processing (1)
  • src/lib/supabase/migrations/20260418100005_add_zora_media_transfer_dedup_trigger.sql

@techeng322 techeng322 merged commit 5addec6 into main Apr 17, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant