Files
pawctioneer-bot/migrations/02_add_bid_active_listing_constraint.sql
2025-09-10 23:51:01 +00:00

16 lines
486 B
SQL

-- 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;