Files
old-zsterminator/db/seeds.rb
2025-08-19 07:24:18 +02:00

41 lines
1.4 KiB
Ruby

# This file should ensure the existence of records required to run the application in every environment (production,
# development, test). The code here should be idempotent so that it can be executed at any point in every environment.
# The data can then be loaded with the bin/rails db:seed command (or created alongside the database with db:setup).
#
# Example:
#
# ["Action", "Comedy", "Drama", "Horror"].each do |genre_name|
# MovieGenre.find_or_create_by!(name: genre_name)
# end
# Create a default company if none exists
default_company = Company.find_or_create_by!(name: 'Default Company') do |company|
company.id_number = 'COMP001'
company.vat_number = 'VAT001'
company.address_line_one = '123 Main Street'
company.city = 'Default City'
company.country = 'Default Country'
end
# Create default teams for the company
teams_data = [
{ name: 'Team Alpha' },
{ name: 'Team Beta' },
{ name: 'Team Gamma' }
]
teams_data.each do |team_attrs|
Team.find_or_create_by!(name: team_attrs[:name], company: default_company)
end
puts "Seeded default company: #{default_company.name}"
puts "Seeded #{default_company.teams.count} teams"
# Create default user for the company
default_user = User.find_or_create_by!(username: 'admin', company: default_company) do |user|
user.email = 'admin@company.ba'
user.password = 'password123'
user.password_confirmation = 'password123'
end
puts "Seeded default user: #{default_user.username} (#{default_user.email})"