defmodule DaProductApp.Repo.Migrations.CreateConfigFileVersions do use Ecto.Migration def change do create table(:config_file_versions) do add :config_type, :string, size: 50, null: false # emv_config | keys_config add :vendor, :string, size: 100, null: false add :model, :string, size: 100, null: false add :version, :string, size: 50, null: false # e.g. "1.0.0", "2025.03.19.001" add :file_path, :string, size: 500, null: false # path on TMS server to the source file add :checksum, :string, size: 64 # SHA-256 hex of the source file add :is_active, :boolean, default: false, null: false # Only one row per config_type+vendor+model should be active at a time add :release_notes, :text add :creator_id, references(:users, on_delete: :nilify_all) timestamps() end # Unique version per config_type + vendor + model create unique_index(:config_file_versions, [:config_type, :vendor, :model, :version], name: :uq_config_file_versions_type_vendor_model_version) # Fast lookup for the active version create index(:config_file_versions, [:config_type, :vendor, :model, :is_active], name: :idx_config_file_versions_active) end end