Skip to content

fix(db): release discount use by code id - #498

Merged
cljiahao merged 15 commits into
stagingfrom
fix/discount-release-by-id
Dec 1, 2026
Merged

cljiahao merged 15 commits into
stagingfrom
fix/discount-release-by-id

Conversation

@cljiahao

@cljiahao cljiahao commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Stacked on #497 (feat/order-ready-email), on #494, on #487. Merge #487, #494, #497, then this.

Migration 0132 adds orders.discount_code_id (FK ON DELETE SET NULL), stores it in place_order, and releases a cancelled order's use by id instead of code text, so a deleted-and-recreated code with the same text is not decremented. A NULL id releases nothing. Backfill only where the text matches exactly one code.

The owner applies migration 0132 by hand after merging.

pgTAP cases added to discount-codes.test.sql (not run locally, no supabase CLI; CI runs db).

🤖 Generated with Claude Code

cljiahao and others added 12 commits December 1, 2026 03:58
… display

Paid vendors (Pro or a running Event Pass) create, switch off and delete
percent or fixed codes with an optional last day and use cap. Customers enter
a code at checkout; place_order re-validates and redeems it atomically so the
client total is never trusted and a total never goes below zero. The order
page and the live board card show the code and amount taken off.

Also adds the service-role-only qkit.issue_reward_code(...) for loopkit,
idempotent on source_ref.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… free cart

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Vendors set an optional minimum per item. The cart starts the item at the
minimum, removes it when decremented below, and the DB refuses customer
orders below it (migration 0130, ORDER_BELOW_MIN).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
place_order refuses any line above 20, so a larger minimum could never be
ordered. The editor, save validation and cart now treat it as invalid or
unreachable, and the editor flags a minimum above the booth's per-order cap.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Checkout gets an unticked opt-in checkbox and email field. The address
lives in service-role-only qkit.order_ready_emails (migration 0131), kept
off orders because that table is in the Realtime publication. Mark Ready
claims the row and sends one Resend email; a send failure never blocks it.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Insert instead of upsert and ignore 23505, look up only unfinished orders,
mark ready-email.ts server-only, drop the vendor-controlled booth name from
the subject, and extend the pgTAP test with service_role insert and delete
returning.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
DELETE ... RETURNING is not valid inside a subquery. Run the service_role
insert and delete before asserting, and assert after reset role.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@cljiahao
cljiahao changed the base branch from feat/order-ready-email to staging December 1, 2026 18:36
cljiahao and others added 3 commits December 2, 2026 02:38
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@cljiahao
cljiahao merged commit 1409340 into staging Dec 1, 2026
11 checks passed
@cljiahao
cljiahao deleted the fix/discount-release-by-id branch December 1, 2026 19:13
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