Files
vault171/db/seeds.rb
David Böhm b7f0c35378
Some checks failed
CI / scan_ruby (push) Has been cancelled
CI / scan_js (push) Has been cancelled
CI / lint (push) Has been cancelled
CI / test (push) Has been cancelled
CI / system-test (push) Has been cancelled
Added some models
User
Item
Department
Categorie
AssignmentLog
Room
2026-05-21 15:36:23 +02:00

48 lines
2.0 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
puts "Bereinige Datenbank..."
AssignmentLog.destroy_all
Item.destroy_all
Room.destroy_all
User.destroy_all
Department.destroy_all
Category.destroy_all
puts "Erstelle Abteilungen..."
dept_it = Department.create!(name: "IT & Infrastruktur", code: "IT")
dept_mkt = Department.create!(name: "Marketing", code: "MKT")
puts "Erstelle Benutzer..."
u1 = User.create!(first_name: "Max", last_name: "Mustermann", email: "max@firma.de", password: "password123123", department: dept_it)
u2 = User.create!(first_name: "Erika", last_name: "Mustermann", email: "erika@firma.de", password: "password123123", department: dept_mkt)
puts "Erstelle Kategorien..."
cat_hardware = Category.create!(name: "Hardware", description: "Laptops und Monitore")
cat_furniture = Category.create!(name: "Möbel", description: "Tische und Stühle")
puts "Erstelle Räume..."
room_101 = Room.create!(name: "Raum 101", building: "Hauptgebäude", floor: "1. OG")
room_lab = Room.create!(name: "Technik-Labor", building: "Werkstatt", floor: "EG")
puts "Erstelle Artikel..."
# Artikel fest an User vergeben
item_laptop = Item.create!(
name: "MacBook Pro 16\"", sku: "MBP16-M3", sticker_id: "10001", serial_number: "C02F1234XYZ",
price: 2500.00, notes: "Entwickler-Laptop", category: cat_hardware, user: u1
)
# Artikel fest an einen Raum vergeben
item_monitor = Item.create!(
name: "Dell 27\" Monitor", sku: "DELL-U27", sticker_id: "10002", serial_number: "CN-0708XX",
price: 450.00, notes: "Fest verbaut an der Wand", category: cat_hardware, room: room_101
)
puts "🎉 Datenbank erfolgreich aufgesetzt!"