defmodule Towerops.Repo.Migrations.CreateDeviceBackupRequests do
  use Ecto.Migration

  def change do
    create table(:device_backup_requests, primary_key: false) do
      add :id, :binary_id, primary_key: true
      add :device_id, references(:devices, type: :binary_id, on_delete: :delete_all), null: false
      add :job_id, :string, null: false
      add :requested_at, :utc_datetime, null: false
      add :completed_at, :utc_datetime
      add :status, :string, null: false
      add :error_message, :text

      timestamps(type: :utc_datetime, updated_at: false)
    end

    create index(:device_backup_requests, [:device_id, :status])
    create index(:device_backup_requests, [:requested_at])
    create index(:device_backup_requests, [:job_id])
  end
end
