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

  def change do
    create table(:preseem_sync_logs, primary_key: false) do
      add :id, :binary_id, primary_key: true

      add :organization_id, references(:organizations, type: :binary_id, on_delete: :delete_all),
        null: false

      add :integration_id, references(:integrations, type: :binary_id, on_delete: :delete_all),
        null: false

      add :status, :string, null: false
      add :records_synced, :integer, default: 0
      add :errors, :map
      add :duration_ms, :integer

      add :inserted_at, :utc_datetime, null: false
    end

    create index(:preseem_sync_logs, [:organization_id])
    create index(:preseem_sync_logs, [:integration_id])
    create index(:preseem_sync_logs, [:inserted_at])
  end
end
