active listing constraint for bidding

This commit is contained in:
Dylan Knutson
2025-09-10 23:51:01 +00:00
parent 212a72c511
commit 4396d367a8
5 changed files with 289 additions and 10 deletions

View File

@@ -0,0 +1,15 @@
-- Add constraint to prevent bids on inactive listings
-- This ensures atomicity at the database level
-- Create a trigger to prevent bids on inactive listings
-- This is more reliable than CHECK constraints in SQLite
CREATE TRIGGER prevent_bid_on_inactive_listing
BEFORE INSERT ON bids
FOR EACH ROW
WHEN (
SELECT COALESCE(is_active, 0) FROM listings WHERE id = NEW.listing_id
) != 1
BEGIN
SELECT RAISE(ABORT, 'Cannot place bid on inactive listing');
END;