build(elixir): update database seed
This commit is contained in:
@@ -51,6 +51,7 @@ A modern, idiomatic Elixir/Phoenix port of the original PHP-based component inve
|
||||
|
||||
2. **Set up the database:**
|
||||
```bash
|
||||
docker run --name components-postgres -p 5432:5432 -e POSTGRES_PASSWORD=fCnPB8VQdPkhJAD29hq6sZEY -d postgres # password: config/dev.exs
|
||||
mix ecto.create
|
||||
mix ecto.migrate
|
||||
mix run priv/repo/seeds.exs
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
# Script for populating the database. You can run it as:
|
||||
# Script for populating the database with sample data. You can run it as:
|
||||
#
|
||||
# mix run priv/repo/seeds.exs
|
||||
#
|
||||
# This seeds file creates:
|
||||
# - Sample categories (with hierarchical subcategories)
|
||||
# - Storage locations (with auto-assigned AprilTag IDs)
|
||||
# - Sample electronic components with proper storage assignments
|
||||
# - Generates all AprilTag SVG files for immediate use
|
||||
#
|
||||
# Inside the script, you can read and write to any of your
|
||||
# repositories directly:
|
||||
#
|
||||
@@ -10,7 +16,7 @@
|
||||
# We recommend using the bang functions (`insert!`, `update!`
|
||||
# and so on) as they will fail if something goes wrong.
|
||||
|
||||
alias ComponentsElixir.{Repo, Inventory}
|
||||
alias ComponentsElixir.{Repo, Inventory, AprilTag}
|
||||
alias ComponentsElixir.Inventory.{Category, Component, StorageLocation}
|
||||
|
||||
# Clear existing data
|
||||
@@ -51,7 +57,7 @@ Repo.delete_all(StorageLocation)
|
||||
|
||||
# Create storage locations
|
||||
{:ok, shelf_a} = Inventory.create_storage_location(%{name: "Shelf A", description: "Main electronics shelf"})
|
||||
{:ok, shelf_b} = Inventory.create_storage_location(%{name: "Shelf B", description: "Components overflow shelf"})
|
||||
{:ok, _shelf_b} = Inventory.create_storage_location(%{name: "Shelf B", description: "Components overflow shelf"})
|
||||
|
||||
# Create drawers on Shelf A
|
||||
{:ok, drawer_a1} = Inventory.create_storage_location(%{
|
||||
@@ -73,7 +79,7 @@ Repo.delete_all(StorageLocation)
|
||||
parent_id: drawer_a1.id
|
||||
})
|
||||
|
||||
{:ok, box_a1_2} = Inventory.create_storage_location(%{
|
||||
{:ok, _box_a1_2} = Inventory.create_storage_location(%{
|
||||
name: "Box 2",
|
||||
description: "SMD resistors",
|
||||
parent_id: drawer_a1.id
|
||||
@@ -192,19 +198,42 @@ IO.puts("Categories: #{length(Inventory.list_categories())}")
|
||||
IO.puts("Storage Locations: #{length(Inventory.list_storage_locations())}")
|
||||
IO.puts("Components: #{length(Inventory.list_components())}")
|
||||
IO.puts("")
|
||||
IO.puts("Sample QR codes for testing:")
|
||||
IO.puts("Sample AprilTag information:")
|
||||
|
||||
# Print some sample QR codes for testing
|
||||
# Print AprilTag information for sample storage locations
|
||||
sample_locations = [
|
||||
Inventory.get_storage_location!(shelf_a.id),
|
||||
Inventory.get_storage_location!(drawer_a1.id),
|
||||
Inventory.get_storage_location!(box_a1_1.id),
|
||||
Inventory.get_storage_location!(box_a2_1.id)
|
||||
]
|
||||
|
||||
Enum.each(sample_locations, fn location ->
|
||||
qr_data = ComponentsElixir.QRCode.generate_qr_data(location)
|
||||
IO.puts("#{location.path}: #{qr_data}")
|
||||
if location.apriltag_id do
|
||||
apriltag_url = AprilTag.get_apriltag_url(location)
|
||||
IO.puts("#{location.path}: AprilTag ID #{location.apriltag_id}")
|
||||
IO.puts(" Download URL: #{apriltag_url}")
|
||||
else
|
||||
IO.puts("#{location.path}: No AprilTag assigned")
|
||||
end
|
||||
end)
|
||||
|
||||
# Generate all AprilTag SVGs for immediate use
|
||||
IO.puts("Generating AprilTag SVG files...")
|
||||
result = AprilTag.generate_all_apriltag_svgs()
|
||||
IO.puts("Generated #{result.success}/#{result.total} AprilTag SVG files")
|
||||
|
||||
IO.puts("")
|
||||
IO.puts("Login with password: changeme (or set AUTH_PASSWORD environment variable)")
|
||||
IO.puts("🎉 Database seeded successfully!")
|
||||
IO.puts("📊 Summary:")
|
||||
IO.puts(" Categories: #{length(Inventory.list_categories())}")
|
||||
IO.puts(" Storage Locations: #{length(Inventory.list_storage_locations())} (with auto-assigned AprilTags)")
|
||||
IO.puts(" Components: #{length(Inventory.list_components())}")
|
||||
IO.puts("")
|
||||
IO.puts("🏷️ AprilTag System:")
|
||||
IO.puts(" - Each storage location has an auto-assigned AprilTag ID (0-586)")
|
||||
IO.puts(" - SVG files available at /apriltags/tag36h11_id_XXX.svg")
|
||||
IO.puts(" - Download AprilTags from storage location management page")
|
||||
IO.puts("")
|
||||
IO.puts("🔐 Login with password: changeme (or set AUTH_PASSWORD environment variable)")
|
||||
IO.puts("🌐 Visit http://localhost:4000 to start using the system!")
|
||||
|
||||
Reference in New Issue
Block a user