4.1 KiB
Plan: Add accountType to Bid for Multi-Domain Auction Support
Context
Users should be able to bid with yellow buzz from .com and green buzz from .red on the same entity in the same auction. Currently, Bid has @@unique([auctionId, userId, entityId]) with no accountType column, so bids from different domains silently merge into one row. BidRecurring has accountType but it's not in the unique constraint, causing the same merge issue.
Migration
New file: prisma/migrations/<timestamp>_add_account_type_to_bid/migration.sql
ALTER TABLE "Bid" ADD COLUMN "accountType" TEXT NOT NULL DEFAULT 'yellow';
ALTER TABLE "Bid" DROP CONSTRAINT "Bid_auctionId_userId_entityId_key";
ALTER TABLE "Bid" ADD CONSTRAINT "Bid_auctionId_userId_entityId_accountType_key"
UNIQUE ("auctionId", "userId", "entityId", "accountType");
ALTER TABLE "BidRecurring" DROP CONSTRAINT "BidRecurring_auctionBaseId_userId_entityId_key";
ALTER TABLE "BidRecurring" ADD CONSTRAINT "BidRecurring_auctionBaseId_userId_entityId_accountType_key"
UNIQUE ("auctionBaseId", "userId", "entityId", "accountType");
All existing rows default to 'yellow'. No data loss.
Schema Changes
File: prisma/schema.full.prisma
Bid: addaccountType String @default("yellow"), change@@uniqueto[auctionId, userId, entityId, accountType]BidRecurring: change@@uniqueto[auctionBaseId, userId, entityId, accountType]
Then run pnpm run db:generate.
Service Changes — src/server/services/auction.service.ts
createBid() (~line 359)
-
Derive
accountTypefrom theaccountTypesparameter:const accountType = accountTypes[0] ?? 'yellow'; -
Add
accountTypeto the bid querywhere(~line 378) so it only finds the bid for this buzz type:bids: { where: { userId, entityId, accountType }, ... } -
Add
accountTypetobid.createdata (~line 521) -
Update
BidRecurringupsertwhere(~line 556) to use the new composite key:auctionBaseId_userId_entityId_accountType: { auctionBaseId, entityId, userId, accountType }
getMyBids() (~line 249)
Add accountType: true to the select so the frontend can distinguish yellow vs green bids.
getMyRecurringBids() (~line 336)
Add accountType: true to the select.
No changes needed
prepareBids()— aggregates byentityIdacross all bids. Yellow + green bids naturally sum together for rankings.counttiebreaker increments by 2 instead of 1 — negligible.deleteBid()— operates bybidId(primary key). User deletes yellow and green bids independently.deleteBidsForModel()/deleteBidsForModelVersion()— bulk operations on all bids for an entity, regardless of type.- All refund logic — uses
transactionIds, buzz service routes refunds to the correct account automatically.
Job Changes — src/server/jobs/handle-auctions.ts
createRecurringBids() (~line 547)
-
Existing bid check (~line 605): add
accountType: recurringBid.accountTypeto thewhereso a green recurring bid isn't skipped because a yellow bid already exists. -
bid.create(~line 679): addaccountType: recurringBid.accountTypeto the data.
Router Changes
None. accountTypes is already server-derived from getAllowedAccountTypes(ctx.features).
Frontend Changes
Minimal — getMyBids and getMyRecurringBids now return accountType. Users with bids from both domains will see two entries in "My Bids" (one yellow, one green). Optionally add a CurrencyIcon with the buzz type to distinguish them visually.
Verification
- Run
pnpm run db:migrate:emptyto create the migration file, paste the SQL - Run
pnpm run db:generateto regenerate Prisma client pnpm run typecheck— verify no type errors from renamed unique constraint- Test: place a bid on .com (yellow), then the same entity from .red (green) — should create two separate bid rows
- Test: recurring bid from .com and .red on the same entity — should create two separate recurring bid rows
- Test: delete the yellow bid — green bid should remain unaffected
- Test: auction rankings should show combined total from both bids