Premiere verison route admin operationnelle

This commit is contained in:
karim hassan
2025-08-25 12:39:54 +00:00
parent eabd0aa50f
commit 38ea5c7da0
21 changed files with 692 additions and 53 deletions

View File

@@ -0,0 +1,4 @@
-- Adds score_a and score_b if not present
ALTER TABLE IF EXISTS matches
ADD COLUMN IF NOT EXISTS score_a INT NOT NULL DEFAULT 0,
ADD COLUMN IF NOT EXISTS score_b INT NOT NULL DEFAULT 0;

13
backend/sql/matches.sql Normal file
View File

@@ -0,0 +1,13 @@
-- Ensure basic matches table exists
CREATE TABLE IF NOT EXISTS matches (
id SERIAL PRIMARY KEY,
tournament_id INT NOT NULL REFERENCES tournaments(id) ON DELETE CASCADE,
player_a_id INT REFERENCES participants(id),
player_b_id INT REFERENCES participants(id),
court TEXT,
start_time TIMESTAMP NULL,
score_a INT DEFAULT 0,
score_b INT DEFAULT 0,
finished BOOLEAN DEFAULT FALSE,
created_at TIMESTAMP DEFAULT now()
);

View File

@@ -0,0 +1,31 @@
-- Migrate existing matches table to expected columns
-- Add columns if they don't exist
ALTER TABLE IF EXISTS matches
ADD COLUMN IF NOT EXISTS player_a_id INT NULL,
ADD COLUMN IF NOT EXISTS player_b_id INT NULL,
ADD COLUMN IF NOT EXISTS court TEXT NULL,
ADD COLUMN IF NOT EXISTS start_time TIMESTAMP NULL,
ADD COLUMN IF NOT EXISTS score_a INT NOT NULL DEFAULT 0,
ADD COLUMN IF NOT EXISTS score_b INT NOT NULL DEFAULT 0,
ADD COLUMN IF NOT EXISTS finished BOOLEAN NOT NULL DEFAULT FALSE;
-- Optionally add FKs if participants table exists
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name='participants') THEN
BEGIN
ALTER TABLE matches
ADD CONSTRAINT IF NOT EXISTS matches_player_a_fk FOREIGN KEY (player_a_id) REFERENCES participants(id) ON DELETE SET NULL,
ADD CONSTRAINT IF NOT EXISTS matches_player_b_fk FOREIGN KEY (player_b_id) REFERENCES participants(id) ON DELETE SET NULL;
EXCEPTION WHEN duplicate_object THEN
-- ignore if constraints already exist
NULL;
END;
END IF;
END $$;
-- Ensure finished default is respected on existing rows
UPDATE matches SET finished = COALESCE(finished, FALSE);
UPDATE matches SET score_a = COALESCE(score_a, 0);
UPDATE matches SET score_b = COALESCE(score_b, 0);

View File

@@ -0,0 +1,6 @@
-- Example seeds (adjust IDs to your existing rows)
INSERT INTO matches (tournament_id, player_a_id, player_b_id, court, start_time)
VALUES
(1, NULL, NULL, 'Court 1', now() + interval '1 hour'),
(1, NULL, NULL, 'Court 2', now() + interval '2 hour')
ON CONFLICT DO NOTHING;