diff --git a/db/seeds.rb b/db/seeds.rb index b66aa3e..c669b0e 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -2,8 +2,295 @@ # This file should contain all the record creation needed to seed the database with its default values. # The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup). -# -# Examples: -# -# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }]) -# Character.create(name: 'Luke', movie: movies.first) + +puts "๐ŸŒฑ Seeding database..." + +# Create admin user +admin_user = User.create!( + name: "admin", + email: "admin@example.com", + password: "password", + password_confirmation: "password", + role: "admin", + confirmed_at: Time.current +) +puts "โœ… Created admin user: #{admin_user.name}" + +# Create sample users +users = [] +5.times do |i| + user = User.create!( + name: "user#{i + 1}", + email: "user#{i + 1}@example.com", + password: "password", + password_confirmation: "password", + role: "member", + atcoder_id: "user#{i + 1}", + atcoder_rating: rand(400..2800), + confirmed_at: Time.current + ) + users << user + puts "โœ… Created user: #{user.name}" +end + +# Create writer user +writer_user = User.create!( + name: "writer", + email: "writer@example.com", + password: "password", + password_confirmation: "password", + role: "writer", + confirmed_at: Time.current +) +puts "โœ… Created writer user: #{writer_user.name}" + +# Create sample contests +past_contest = Contest.create!( + slug: "sample-contest-2024", + name: "Sample Contest 2024", + description: "ใ“ใ‚Œใฏใ‚ตใƒณใƒ—ใƒซใ‚ณใƒณใƒ†ใ‚นใƒˆใงใ™ใ€‚", + kind: "normal", + allow_open_registration: true, + allow_team_registration: false, + standings_mode: 1, + penalty_time: 5, + start_at: 1.month.ago, + end_at: 1.month.ago + 3.hours, + permanent: false, + official_mode: true +) +puts "โœ… Created past contest: #{past_contest.name}" + +upcoming_contest = Contest.create!( + slug: "upcoming-contest", + name: "Upcoming Contest", + description: "ใ“ใ‚Œใ‹ใ‚‰้–‹ๅ‚ฌใ•ใ‚Œใ‚‹ใ‚ณใƒณใƒ†ใ‚นใƒˆใงใ™ใ€‚", + kind: "normal", + allow_open_registration: true, + allow_team_registration: true, + standings_mode: 1, + penalty_time: 5, + start_at: 1.week.from_now, + end_at: 1.week.from_now + 3.hours, + permanent: false, + official_mode: true +) +puts "โœ… Created upcoming contest: #{upcoming_contest.name}" + +practice_contest = Contest.create!( + slug: "practice", + name: "Practice Contest", + description: "็ทด็ฟ’็”จใฎใ‚ณใƒณใƒ†ใ‚นใƒˆใงใ™ใ€‚ใ„ใคใงใ‚‚ๅ‚ๅŠ ใงใใพใ™ใ€‚", + kind: "normal", + allow_open_registration: true, + allow_team_registration: false, + standings_mode: 1, + penalty_time: 0, + start_at: 1.year.ago, + end_at: nil, + permanent: true, + official_mode: false +) +puts "โœ… Created practice contest: #{practice_contest.name}" + +# Create sample problems +problem_a = Problem.create!( + slug: "sample-a", + name: "A + B Problem", + contest_id: past_contest.id, + writer_user_id: writer_user.id, + position: "A", + uuid: SecureRandom.uuid, + difficulty: "beginner", + execution_time_limit: 2000, + submission_limit_1: 5, + submission_limit_2: 60, + statement: "2ใคใฎๆ•ดๆ•ฐ A, B ใŒไธŽใˆใ‚‰ใ‚Œใพใ™ใ€‚A + B ใ‚’ๅ‡บๅŠ›ใ—ใฆใใ ใ•ใ„ใ€‚", + constraints: "1 โ‰ค A, B โ‰ค 1000", + input_format: "A B", + output_format: "A + B ใฎๅ€ค" +) +puts "โœ… Created problem: #{problem_a.name}" + +problem_b = Problem.create!( + slug: "sample-b", + name: "Factorial", + contest_id: past_contest.id, + writer_user_id: writer_user.id, + position: "B", + uuid: SecureRandom.uuid, + difficulty: "easy", + execution_time_limit: 2000, + submission_limit_1: 5, + submission_limit_2: 60, + statement: "ๆญฃใฎๆ•ดๆ•ฐ N ใŒไธŽใˆใ‚‰ใ‚Œใพใ™ใ€‚N! (N ใฎ้šŽไน—) ใ‚’ๅ‡บๅŠ›ใ—ใฆใใ ใ•ใ„ใ€‚", + constraints: "1 โ‰ค N โ‰ค 10", + input_format: "N", + output_format: "N! ใฎๅ€ค" +) +puts "โœ… Created problem: #{problem_b.name}" + +practice_problem = Problem.create!( + slug: "hello-world", + name: "Hello World", + contest_id: practice_contest.id, + writer_user_id: writer_user.id, + position: "A", + uuid: SecureRandom.uuid, + difficulty: "beginner", + execution_time_limit: 1000, + submission_limit_1: 10, + submission_limit_2: 100, + statement: "\"Hello World\" ใ‚’ๅ‡บๅŠ›ใ—ใฆใใ ใ•ใ„ใ€‚", + constraints: "็‰นใซใชใ—", + input_format: "ๅ…ฅๅŠ›ใฏใ‚ใ‚Šใพใ›ใ‚“ใ€‚", + output_format: "Hello World" +) +puts "โœ… Created practice problem: #{practice_problem.name}" + +# Create testcases for problems +# A + B Problem testcases +testcase_a1 = Testcase.create!( + problem_id: problem_a.id, + name: "sample_01", + input: "1 2", + output: "3", + explanation: "1 + 2 = 3" +) + +testcase_a2 = Testcase.create!( + problem_id: problem_a.id, + name: "sample_02", + input: "100 200", + output: "300", + explanation: "100 + 200 = 300" +) + +# Factorial testcases +testcase_b1 = Testcase.create!( + problem_id: problem_b.id, + name: "sample_01", + input: "3", + output: "6", + explanation: "3! = 3 ร— 2 ร— 1 = 6" +) + +testcase_b2 = Testcase.create!( + problem_id: problem_b.id, + name: "sample_02", + input: "5", + output: "120", + explanation: "5! = 5 ร— 4 ร— 3 ร— 2 ร— 1 = 120" +) + +# Hello World testcase +testcase_hello = Testcase.create!( + problem_id: practice_problem.id, + name: "sample_01", + input: "", + output: "Hello World", + explanation: "Hello World ใ‚’ๅ‡บๅŠ›ใ™ใ‚‹" +) + +puts "โœ… Created testcases" + +# Create testcase sets +testcase_set_a = TestcaseSet.create!( + problem_id: problem_a.id, + name: "All", + points: 100, + aggregate_type: 0, + is_sample: true +) + +testcase_set_b = TestcaseSet.create!( + problem_id: problem_b.id, + name: "All", + points: 100, + aggregate_type: 0, + is_sample: true +) + +testcase_set_hello = TestcaseSet.create!( + problem_id: practice_problem.id, + name: "All", + points: 100, + aggregate_type: 0, + is_sample: true +) + +# Associate testcases with testcase sets +TestcaseTestcaseSet.create!(testcase_id: testcase_a1.id, testcase_set_id: testcase_set_a.id) +TestcaseTestcaseSet.create!(testcase_id: testcase_a2.id, testcase_set_id: testcase_set_a.id) +TestcaseTestcaseSet.create!(testcase_id: testcase_b1.id, testcase_set_id: testcase_set_b.id) +TestcaseTestcaseSet.create!(testcase_id: testcase_b2.id, testcase_set_id: testcase_set_b.id) +TestcaseTestcaseSet.create!(testcase_id: testcase_hello.id, testcase_set_id: testcase_set_hello.id) + +puts "โœ… Created testcase sets and associations" + +# Create registrations for past contest +users.each do |user| + Registration.create!( + user_id: user.id, + contest_id: past_contest.id, + open_registration: true + ) +end +puts "โœ… Created registrations for past contest" + +# Create some sample submissions +users.first(3).each_with_index do |user, index| + Submission.create!( + user_id: user.id, + problem_id: problem_a.id, + path: "submissions/#{user.id}/#{problem_a.id}/main.cpp", + status: index == 0 ? "AC" : ["WA", "TLE", "RE"].sample, + point: index == 0 ? 100 : 0, + execution_time: rand(100..1500), + execution_memory: rand(1000..50000), + lang: "cpp", + public: true + ) +end +puts "โœ… Created sample submissions" + +# Create contest admins +ContestAdmin.create!( + contest_id: past_contest.id, + user_id: admin_user.id +) + +ContestAdmin.create!( + contest_id: upcoming_contest.id, + user_id: admin_user.id +) + +ContestAdmin.create!( + contest_id: practice_contest.id, + user_id: admin_user.id +) +puts "โœ… Created contest admins" + +# Create sample posts +Post.create!( + title: "ใ‚ตใ‚คใƒˆใ‚ชใƒผใƒ—ใƒณใฎใŠ็Ÿฅใ‚‰ใ›", + content: "็ซถๆŠ€ใƒ—ใƒญใ‚ฐใƒฉใƒŸใƒณใ‚ฐใ‚ชใƒณใƒฉใ‚คใƒณใ‚ธใƒฃใƒƒใ‚ธใ‚ตใ‚คใƒˆใŒใ‚ชใƒผใƒ—ใƒณใ—ใพใ—ใŸ๏ผ\n\nใ“ใฎใ‚ตใ‚คใƒˆใงใฏไปฅไธ‹ใฎใ“ใจใŒใงใใพใ™๏ผš\n- ใƒ—ใƒญใ‚ฐใƒฉใƒŸใƒณใ‚ฐใ‚ณใƒณใƒ†ใ‚นใƒˆใซๅ‚ๅŠ \n- ๅ•้กŒใฎ็ทด็ฟ’\n- ไป–ใฎๅ‚ๅŠ ่€…ใจใฎไบคๆต\n\nใœใฒใ”ๅˆฉ็”จใใ ใ•ใ„๏ผ", + public_status: "public" +) + +Post.create!( + title: "ๅˆๅ›žใ‚ณใƒณใƒ†ใ‚นใƒˆ้–‹ๅ‚ฌใฎใŠ็Ÿฅใ‚‰ใ›", + content: "่จ˜ๅฟตใ™ในใ็ฌฌ1ๅ›žใ‚ณใƒณใƒ†ใ‚นใƒˆใ‚’้–‹ๅ‚ฌใ—ใพใ™๏ผ\n\nๆ—ฅๆ™‚๏ผšๆฅ้€ฑใฎๅœŸๆ›œๆ—ฅ 20:00-23:00\n้›ฃๆ˜“ๅบฆ๏ผšๅˆๅฟƒ่€…ใ€œไธญ็ดš่€…ๅ‘ใ‘\n\n็š†ๆง˜ใฎใ”ๅ‚ๅŠ ใ‚’ใŠๅพ…ใกใ—ใฆใŠใ‚Šใพใ™ใ€‚", + public_status: "public" +) +puts "โœ… Created sample posts" + +puts "๐ŸŽ‰ Database seeded successfully!" +puts "" +puts "๐Ÿ“Š Summary:" +puts "- Users: #{User.count}" +puts "- Contests: #{Contest.count}" +puts "- Problems: #{Problem.count}" +puts "- Testcases: #{Testcase.count}" +puts "- Submissions: #{Submission.count}" +puts "- Posts: #{Post.count}" \ No newline at end of file