Added some models
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

User
Item
Department
Categorie
AssignmentLog
Room
This commit is contained in:
2026-05-21 15:36:23 +02:00
parent 7b02520b6c
commit b7f0c35378
27 changed files with 387 additions and 2 deletions

View File

@@ -0,0 +1,10 @@
class CreateCategories < ActiveRecord::Migration[8.1]
def change
create_table :categories do |t|
t.string :name
t.text :description
t.timestamps
end
end
end

View File

@@ -0,0 +1,10 @@
class CreateDepartments < ActiveRecord::Migration[8.1]
def change
create_table :departments do |t|
t.string :name
t.string :code
t.timestamps
end
end
end

View File

@@ -0,0 +1,19 @@
class CreateItems < ActiveRecord::Migration[8.1]
def change
create_table :items do |t|
t.string :name
t.string :sku
t.string :sticker_id
t.string :serial_number
t.decimal :price, precision: 8, scale: 2
t.text :notes
t.references :category, foreign_key: true
t.references :user, foreign_key: true
t.references :room, foreign_key: true
t.timestamps
end
add_index :items, :sticker_id, unique: true
add_index :items, :serial_number, unique: true
end
end

View File

@@ -0,0 +1,13 @@
class CreateAssignmentLogs < ActiveRecord::Migration[8.1]
def change
create_table :assignment_logs do |t|
t.references :item, foreign_key: true
t.references :user, foreign_key: true
t.references :room, foreign_key: true
t.datetime :assigned_at
t.datetime :returned_at
t.timestamps
end
end
end

View File

@@ -0,0 +1,9 @@
class AddDetailsToUsers < ActiveRecord::Migration[7.1]
def change
add_column :users, :first_name, :string
add_column :users, :last_name, :string
# WICHTIG: null: true erlaubt es, dass alte User erst einmal ohne Abteilung migriert werden
add_reference :users, :department, null: true, foreign_key: true
end
end

View File

@@ -0,0 +1,11 @@
class CreateRooms < ActiveRecord::Migration[8.1]
def change
create_table :rooms do |t|
t.string :name
t.string :building
t.string :floor
t.timestamps
end
end
end

67
db/schema.rb generated
View File

@@ -10,7 +10,34 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[8.1].define(version: 2026_05_20_205436) do
ActiveRecord::Schema[8.1].define(version: 2026_05_21_125254) do
create_table "assignment_logs", force: :cascade do |t|
t.datetime "assigned_at"
t.datetime "created_at", null: false
t.integer "item_id"
t.datetime "returned_at"
t.integer "room_id"
t.datetime "updated_at", null: false
t.integer "user_id"
t.index ["item_id"], name: "index_assignment_logs_on_item_id"
t.index ["room_id"], name: "index_assignment_logs_on_room_id"
t.index ["user_id"], name: "index_assignment_logs_on_user_id"
end
create_table "categories", force: :cascade do |t|
t.datetime "created_at", null: false
t.text "description"
t.string "name"
t.datetime "updated_at", null: false
end
create_table "departments", force: :cascade do |t|
t.string "code"
t.datetime "created_at", null: false
t.string "name"
t.datetime "updated_at", null: false
end
create_table "events", force: :cascade do |t|
t.string "action", null: false
t.datetime "created_at", null: false
@@ -21,6 +48,33 @@ ActiveRecord::Schema[8.1].define(version: 2026_05_20_205436) do
t.index ["user_id"], name: "index_events_on_user_id"
end
create_table "items", force: :cascade do |t|
t.integer "category_id"
t.datetime "created_at", null: false
t.string "name"
t.text "notes"
t.decimal "price", precision: 8, scale: 2
t.integer "room_id"
t.string "serial_number"
t.string "sku"
t.string "sticker_id"
t.datetime "updated_at", null: false
t.integer "user_id"
t.index ["category_id"], name: "index_items_on_category_id"
t.index ["room_id"], name: "index_items_on_room_id"
t.index ["serial_number"], name: "index_items_on_serial_number", unique: true
t.index ["sticker_id"], name: "index_items_on_sticker_id", unique: true
t.index ["user_id"], name: "index_items_on_user_id"
end
create_table "rooms", force: :cascade do |t|
t.string "building"
t.datetime "created_at", null: false
t.string "floor"
t.string "name"
t.datetime "updated_at", null: false
end
create_table "sessions", force: :cascade do |t|
t.datetime "created_at", null: false
t.string "ip_address"
@@ -32,13 +86,24 @@ ActiveRecord::Schema[8.1].define(version: 2026_05_20_205436) do
create_table "users", force: :cascade do |t|
t.datetime "created_at", null: false
t.integer "department_id"
t.string "email", null: false
t.string "first_name"
t.string "last_name"
t.string "password_digest", null: false
t.datetime "updated_at", null: false
t.boolean "verified", default: false, null: false
t.index ["department_id"], name: "index_users_on_department_id"
t.index ["email"], name: "index_users_on_email", unique: true
end
add_foreign_key "assignment_logs", "items"
add_foreign_key "assignment_logs", "rooms"
add_foreign_key "assignment_logs", "users"
add_foreign_key "events", "users"
add_foreign_key "items", "categories"
add_foreign_key "items", "rooms"
add_foreign_key "items", "users"
add_foreign_key "sessions", "users"
add_foreign_key "users", "departments"
end

View File

@@ -7,3 +7,41 @@
# ["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!"