active listing constraint for bidding
This commit is contained in:
15
migrations/02_add_bid_active_listing_constraint.sql
Normal file
15
migrations/02_add_bid_active_listing_constraint.sql
Normal 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;
|
||||
|
||||
Reference in New Issue
Block a user