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

  def change do
    create table(:device_mikrotik_backups, 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 :config_compressed, :binary, null: false
      add :config_hash, :string, null: false
      add :config_hash_normalized, :string, null: false
      add :config_size_bytes, :integer
      add :compressed_size_bytes, :integer
      add :backed_up_at, :utc_datetime, null: false
      add :trigger_source, :string, default: "daily_cron"

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

    create index(:device_mikrotik_backups, [:device_id, :backed_up_at])
  end
end
