feat(elixir): storage location system

This commit is contained in:
Schuwi
2025-09-14 15:20:25 +02:00
parent b9126c286f
commit 9d090859e8
14 changed files with 1517 additions and 160 deletions

View File

@@ -0,0 +1,29 @@
defmodule ComponentsElixir.Repo.Migrations.CreateStorageLocations do
use Ecto.Migration
def change do
create table(:storage_locations) do
add :name, :string, null: false
add :description, :text
add :qr_code, :string, null: false
add :level, :integer, default: 0
add :path, :text, null: false
add :is_active, :boolean, default: true
add :parent_id, references(:storage_locations, on_delete: :restrict)
timestamps()
end
create unique_index(:storage_locations, [:qr_code])
create index(:storage_locations, [:parent_id])
create index(:storage_locations, [:level])
create unique_index(:storage_locations, [:name, :parent_id])
# Enable trigram extension for path searching
execute "CREATE EXTENSION IF NOT EXISTS pg_trgm", "DROP EXTENSION IF EXISTS pg_trgm"
# GIN index for fast path-based searches
execute "CREATE INDEX storage_locations_path_gin_idx ON storage_locations USING gin(path gin_trgm_ops)",
"DROP INDEX storage_locations_path_gin_idx"
end
end

View File

@@ -0,0 +1,16 @@
defmodule ComponentsElixir.Repo.Migrations.AddStorageLocationToComponents do
use Ecto.Migration
def change do
alter table(:components) do
add :storage_location_id, references(:storage_locations, on_delete: :nilify_all)
add :legacy_position, :string
end
create index(:components, [:storage_location_id])
# Copy existing position data to legacy_position for migration
execute "UPDATE components SET legacy_position = position WHERE position IS NOT NULL",
"UPDATE components SET position = legacy_position WHERE legacy_position IS NOT NULL"
end
end

View File

@@ -0,0 +1,10 @@
defmodule ComponentsElixir.Repo.Migrations.RemoveNotNullConstraintsFromStorageLocations do
use Ecto.Migration
def change do
alter table(:storage_locations) do
modify :level, :integer, null: true
modify :path, :string, null: true
end
end
end