68 lines
3 KiB
PL/PgSQL
68 lines
3 KiB
PL/PgSQL
-- 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, status) VALUES
|
|
(1, '1000', 'K-1042', 2, 'Shimano Nexus 8', 'BAT-A12', 'in_service'),
|
|
(2, '2000', 'K-1043', 2, 'Shimano Nexus 8', 'BAT-A13', 'in_service'),
|
|
(3, '3000', 'K-1044', 1, 'Rohloff Speedhub', NULL, 'out_of_service'),
|
|
(4, '4000', 'K-1042', 2, 'Shimano Nexus 8', 'BAT-A12', 'in_service'),
|
|
(5, '5000', 'K-1043', 2, 'Shimano Nexus 8', 'BAT-A13', 'in_service')
|
|
ON CONFLICT DO NOTHING;
|
|
|
|
INSERT INTO public.reservations
|
|
(id, unit_id, start_time, end_time, requester_id, telegram, "description", status)
|
|
SELECT r.id, u.id, r.start_time, r.end_time, r.requester_id, r.telegram, r."description", r.status
|
|
FROM (VALUES
|
|
(1, 'agepoly', '2026-09-01 08:00:00+02'::timestamptz, '2026-09-01 18:00:00+02'::timestamptz,
|
|
1, '@alice_martin', 'Transport du matériel pour la rentrée', 'approved'::reservation_status),
|
|
(2, 'clic', '2026-09-05 09:00:00+02'::timestamptz, '2026-09-06 17:00:00+02'::timestamptz,
|
|
3, '@chloe_favre', 'Déménagement du stock de la commission', 'requested'::reservation_status)
|
|
) AS r (id, unit_name, start_time, end_time, requester_id, telegram, "description", 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)
|
|
ON CONFLICT DO NOTHING;
|
|
|
|
INSERT INTO public.reservations_bikes (reservation_id, bike_id) VALUES
|
|
(1, 1), (1, 2), (2, 1)
|
|
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;
|