03-scores.sql (936B)
1 CREATE TABLE public.scores ( 2 id bigint NOT NULL, 3 created_at timestamp with time zone DEFAULT now(), 4 athlete bigint NOT NULL, 5 judge bigint NOT NULL, 6 score double precision, 7 heat bigint NOT NULL 8 ); 9 10 ALTER TABLE public.scores ALTER COLUMN id ADD GENERATED BY DEFAULT AS IDENTITY ( 11 SEQUENCE NAME public.score_id_seq 12 START WITH 1 13 INCREMENT BY 1 14 NO MINVALUE 15 NO MAXVALUE 16 CACHE 1 17 ); 18 19 ALTER TABLE ONLY public.scores 20 ADD CONSTRAINT scores_pkey PRIMARY KEY (athlete, judge, heat); 21 22 ALTER TABLE ONLY public.scores 23 ADD CONSTRAINT scores_athlete_fkey FOREIGN KEY (athlete) REFERENCES public.athletes(id) ON DELETE CASCADE; 24 25 ALTER TABLE ONLY public.scores 26 ADD CONSTRAINT scores_heat_fkey FOREIGN KEY (heat) REFERENCES public.heats(id) ON DELETE CASCADE; 27 28 ALTER TABLE ONLY public.scores 29 ADD CONSTRAINT scores_judge_fkey FOREIGN KEY (judge) REFERENCES public.judges(id) ON DELETE CASCADE;