From 2755995641da86b0bea4080f56b9583a1516e1d5 Mon Sep 17 00:00:00 2001 From: Bitha17 <16521076@mahasiswa.itb.ac.id> Date: Thu, 16 Nov 2023 01:38:01 +0700 Subject: [PATCH] feat: db seeding --- database/6-seed.sql | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 database/6-seed.sql diff --git a/database/6-seed.sql b/database/6-seed.sql new file mode 100644 index 0000000..75d29b1 --- /dev/null +++ b/database/6-seed.sql @@ -0,0 +1,36 @@ +-- Generate and insert 100 dummy events with random data +DO $$ +DECLARE + i INT; +BEGIN + FOR i IN 1..100 LOOP + INSERT INTO events (event_name, event_stock, event_price, event_date, event_location, gambar, vid) + VALUES ( + 'Event ' || i, + FLOOR(RANDOM() * 10) + 1, + FLOOR(RANDOM() * 91) + 10, + NOW() + (i || ' days')::INTERVAL, + 'Location ' || i, + 'assets/images/' || (i % 16 + 1) || '.jpg', + 'assets/videos/video.mp4' + ); + + -- Generate and insert tickets corresponding to the event's event_stock + FOR j IN 1..(FLOOR(RANDOM() * 10) + 1) LOOP + INSERT INTO tickets (ticket_name, event_id) + VALUES ( + 'Ticket ' || j || ' for Event ' || i, + (SELECT MAX(event_id) FROM events) + ); + END LOOP; + END LOOP; +END $$; + +-- Insert user data +INSERT INTO users (user_name, username, user_email, user_hashedPass, isAdmin) +VALUES + ('John Doe', 'john_doe', 'john@example.com', crypt('password_1', gen_salt('bf', 8)), 1), + ('Jane Smith', 'jane_smith', 'jane@example.com', crypt('password_2', gen_salt('bf', 8)), 0), + ('Admin User', 'admin_user', 'admin@example.com', crypt('password_3', gen_salt('bf', 8)), 1), + ('Alice Johnson', 'alice', 'alice@example.com', crypt('password_4', gen_salt('bf', 8)), 0), + ('Bob Williams', 'bob', 'bob@example.com', crypt('password_5', gen_salt('bf', 8)), 0); -- GitLab