Initial commit
**Motivations:** - Initialisation du versionning git pour le projet **Root causes:** - N/A (Nouveau projet) **Correctifs:** - N/A **Evolutions:** - Structure initiale du projet - Ajout du .gitignore **Pages affectées:** - Tous les fichiers
This commit is contained in:
34
server/migrations/001_sale_listings.sql
Normal file
34
server/migrations/001_sale_listings.sql
Normal file
@@ -0,0 +1,34 @@
|
||||
-- Phase 10: sale listings and bids (enchères)
|
||||
-- Run after schema.sql (e.g. psql -d builazoo -f server/migrations/001_sale_listings.sql)
|
||||
|
||||
CREATE TABLE IF NOT EXISTS sale_listings (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
seller_zoo_id UUID NOT NULL REFERENCES zoos(id) ON DELETE CASCADE,
|
||||
animal_id TEXT NOT NULL,
|
||||
is_baby BOOLEAN NOT NULL,
|
||||
initial_price INTEGER NOT NULL,
|
||||
end_at TIMESTAMPTZ NOT NULL,
|
||||
status TEXT NOT NULL DEFAULT 'active' CHECK (status IN ('active', 'sold', 'expired', 'rejected')),
|
||||
best_bid_amount INTEGER,
|
||||
best_bidder_zoo_id UUID REFERENCES zoos(id) ON DELETE SET NULL,
|
||||
sold_at TIMESTAMPTZ,
|
||||
reproduction_score_at_sale NUMERIC,
|
||||
delivered_at TIMESTAMPTZ,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS sale_listings_seller ON sale_listings(seller_zoo_id);
|
||||
CREATE INDEX IF NOT EXISTS sale_listings_status ON sale_listings(status);
|
||||
CREATE INDEX IF NOT EXISTS sale_listings_end_at ON sale_listings(end_at);
|
||||
CREATE INDEX IF NOT EXISTS sale_listings_best_bidder ON sale_listings(best_bidder_zoo_id);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS sale_bids (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
listing_id UUID NOT NULL REFERENCES sale_listings(id) ON DELETE CASCADE,
|
||||
bidder_zoo_id UUID NOT NULL REFERENCES zoos(id) ON DELETE CASCADE,
|
||||
amount INTEGER NOT NULL,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||
UNIQUE(listing_id, bidder_zoo_id)
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS sale_bids_listing ON sale_bids(listing_id);
|
||||
12
server/migrations/002_sale_listings_validated_at.sql
Normal file
12
server/migrations/002_sale_listings_validated_at.sql
Normal file
@@ -0,0 +1,12 @@
|
||||
-- BLOC 2: Deferred validation (10 min) for sales. Run after 001_sale_listings.sql.
|
||||
-- Adds validated_at: when accept is called, sold_at = now(), validated_at = now() + 10 minutes.
|
||||
-- Coins are transferred only when validated_at <= now() (processed by processValidatedSales).
|
||||
-- Buyer can deliver only after status = 'validated'.
|
||||
|
||||
ALTER TABLE sale_listings ADD COLUMN IF NOT EXISTS validated_at TIMESTAMPTZ;
|
||||
|
||||
ALTER TABLE sale_listings DROP CONSTRAINT IF EXISTS sale_listings_status_check;
|
||||
ALTER TABLE sale_listings ADD CONSTRAINT sale_listings_status_check
|
||||
CHECK (status IN ('active', 'sold', 'expired', 'rejected', 'validated'));
|
||||
|
||||
COMMENT ON COLUMN sale_listings.validated_at IS 'When the sale becomes validated (coins transfer allowed). Set at accept to now() + 10 minutes; after processValidatedSales runs, status becomes validated.';
|
||||
Reference in New Issue
Block a user