-- Development data. Apply with: -- psql "$DATABASE_URL" -f db/seed.sql BEGIN; INSERT INTO public.users (id, external_id, firstname, "name", email, oidc_sub, admin) VALUES (1, '100001', 'Alice', 'Martin', 'alice.martin@epfl.ch', 'oidc-sub-alice', TRUE), (2, '100002', 'Bob', 'Dupont', 'bob.dupont@epfl.ch', 'oidc-sub-bob', FALSE), (3, NULL, 'Chloé', 'Favre', 'chloe.favre@epfl.ch', 'oidc-sub-chloe', FALSE) ON CONFLICT DO NOTHING; -- Units are Whiskey's "groups". In real life the rows are created on the fly at -- login; these are placeholders for development. INSERT INTO public.units ("name") VALUES ('agepoly'), ('clic'), ('S4S'), ('Balélec') ON CONFLICT ("name") DO NOTHING; -- Resolved by name so the seed never depends on generated ids INSERT INTO public.units_users (user_id, unit_id) SELECT membership.user_id, u.id FROM (VALUES (1, 'agepoly'), (2, 'agepoly'), (2, 'clic'), (1, 'S4S'), (1, 'Balélec'), (3, 'clic') ) AS membership (user_id, unit_name) JOIN public.units u ON u."name" = membership.unit_name ON CONFLICT DO NOTHING; INSERT INTO public.bikes (id, "name", key_number, key_quantity, drivetrain, battery, "size", status) VALUES (1, '1000', 'K-1042', 2, 'Shimano Nexus 8', 'BAT-A12', 'large', 'in_service'), (2, '2000', 'K-1043', 2, 'Shimano Nexus 8', 'BAT-A13', 'large', 'in_service'), (3, '3000', 'K-1044', 1, 'Rohloff Speedhub', NULL, 'small', 'out_of_service'), (4, '4000', 'K-1042', 2, 'Shimano Nexus 8', 'BAT-A12', 'small', 'in_service'), (5, '5000', 'K-1043', 2, 'Shimano Nexus 8', 'BAT-A13', 'small', 'in_service') ON CONFLICT DO NOTHING; -- Reservations across the current week, one per status, so the admin page and -- the calendar always have something to show. Times are relative to `now()`. INSERT INTO public.reservations (id, unit_id, start_time, end_time, requester_id, telegram, "description", linka_emails, status) SELECT r.id, u.id, r.start_time, r.end_time, r.requester_id, r.telegram, r."description", r.linka_emails, r.status FROM (VALUES (1, 'agepoly', date_trunc('day', now()) - interval '1 day' + interval '8 hours', date_trunc('day', now()) + interval '1 day' + interval '18 hours', 1, '@alice_martin', 'Transport du matériel pour la rentrée', ARRAY['alice.martin@epfl.ch'], 'ongoing'::reservation_status), (2, 'clic', date_trunc('day', now()) + interval '1 day' + interval '9 hours', date_trunc('day', now()) + interval '2 days' + interval '17 hours', 3, '@chloe_favre', 'Déménagement du stock de la commission', ARRAY['chloe.favre@epfl.ch'], 'approved'::reservation_status), (3, 'agepoly', date_trunc('day', now()) + interval '3 days' + interval '10 hours', date_trunc('day', now()) + interval '3 days' + interval '19 hours', 2, '@bob_dupont', 'Livraison des boissons pour la soirée', ARRAY['bob.dupont@epfl.ch','alice.martin@epfl.ch'], 'requested'::reservation_status), (4, 'clic', date_trunc('day', now()) + interval '4 days' + interval '7 hours', date_trunc('day', now()) + interval '4 days' + interval '12 hours', 3, '@chloe_favre', 'Récupération de matériel informatique', ARRAY['chloe.favre@epfl.ch'], 'requested'::reservation_status), (5, 'agepoly', date_trunc('day', now()) - interval '20 days' + interval '9 hours', date_trunc('day', now()) - interval '19 days' + interval '18 hours', 1, '@alice_martin', 'Ancienne sortie, archivée', ARRAY['alice.martin@epfl.ch'], 'archived'::reservation_status), (6, 'clic', date_trunc('day', now()) + interval '6 days' + interval '14 hours', date_trunc('day', now()) + interval '6 days' + interval '18 hours', 2, '@bob_dupont', 'Annulée faute de conducteur', ARRAY['bob.dupont@epfl.ch'], 'cancelled'::reservation_status), -- Wants the 5000 while reservation 2 still holds it, so the admin page has -- a conflict to warn about without anybody having to build one by hand (7, 'S4S', date_trunc('day', now()) + interval '1 day' + interval '14 hours', date_trunc('day', now()) + interval '2 days' + interval '10 hours', 1, '@alice_martin', 'Stand de la journée portes ouvertes', ARRAY['alice.martin@epfl.ch'], 'requested'::reservation_status) ) AS r (id, unit_name, start_time, end_time, requester_id, telegram, "description", linka_emails, status) JOIN public.units u ON u."name" = r.unit_name ON CONFLICT DO NOTHING; INSERT INTO public.reservations_users (reservation_id, user_id) VALUES (1, 1), (1, 2), (2, 3), (3, 2), (3, 1), (4, 3), (5, 1), (6, 2), (7, 1) ON CONFLICT DO NOTHING; -- The bikes each reservation holds. The two period columns are normally NULL, -- which means "the reservation's own period"; they are only filled when a bike -- is handed over early to settle a conflict, as reservation 1 does with the -- 2000 — that one is given back at noon today rather than tomorrow evening. INSERT INTO public.reservations_bikes (reservation_id, bike_id, start_time, end_time) VALUES (1, 1, NULL::timestamptz, NULL::timestamptz), (1, 2, date_trunc('day', now()) - interval '1 day' + interval '8 hours', date_trunc('day', now()) + interval '12 hours'), (2, 3, NULL, NULL), -- Held by reservation 2, and wanted by reservation 7 at the same time (2, 5, NULL, NULL), (3, 1, NULL, NULL), (3, 4, NULL, NULL), (4, 2, NULL, NULL), (5, 5, NULL, NULL), (6, 4, NULL, NULL), (7, 5, NULL, NULL) ON CONFLICT DO NOTHING; -- Keep the sequences in sync with the explicit ids inserted above SELECT setval('public.units_id_seq', (SELECT COALESCE(MAX(id), 1) FROM public.units)); SELECT setval('public.users_id_seq', (SELECT COALESCE(MAX(id), 1) FROM public.users)); SELECT setval('public.bikes_id_seq', (SELECT COALESCE(MAX(id), 1) FROM public.bikes)); SELECT setval('public.reservations_id_seq', (SELECT COALESCE(MAX(id), 1) FROM public.reservations)); COMMIT;