867 B · text History b868907
defmodule GitGud.Repo.Migrations.AddUpstreamAutoSync do
  use Ecto.Migration

  # Scheduled upstream sync, opt-in per repository.
  #
  # `upstream_sync_error` holds the last scheduled failure so the repo's
  # settings page can say why nothing has moved — a scheduled job has
  # nobody watching it, and a silent failure is indistinguishable from
  # an upstream that simply hasn't changed.
  def change do
    alter table(:repositories) do
      add :upstream_auto_sync, :boolean, null: false, default: false
      add :upstream_sync_error, :string
    end

    # The scheduler walks exactly this set, so keep it an index scan
    # rather than a repo-table sweep.
    create index(:repositories, [:upstream_auto_sync],
             where: "upstream_auto_sync AND upstream_url IS NOT NULL",
             name: :repositories_auto_sync_index
           )
  end
end