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