1.4 KiB · text 5af55d9
defmodule GitGud.Repo.Migrations.CreateCommitStatuses do
use Ecto.Migration
@moduledoc """
Per-commit CI / build statuses. Each row is one (provider, commit)
pair — multiple providers can post against the same SHA and they
appear stacked on commit + PR views (matching GitHub / Forgejo
conventions).
Populated automatically by `Workflows.update_run_commit_status/1`
on every workflow_run status transition; the `context` is keyed by
workflow path so multiple workflows on the same commit don't
collide.
Future use: federation peers can POST statuses against a remote
commit via the same table.
Storing `sha` as a 20-byte binary to match `workflow_runs.head_sha`.
"""
def change do
create table(:commit_statuses) do
add :repository_id, references(:repositories, on_delete: :delete_all), null: false
add :sha, :binary, null: false
add :context, :string, null: false, size: 255
add :state, :string, null: false, size: 16
add :description, :string, size: 512
add :target_url, :string, size: 1024
timestamps(type: :utc_datetime)
end
create unique_index(:commit_statuses, [:repository_id, :sha, :context])
create index(:commit_statuses, [:repository_id, :sha])
create constraint(:commit_statuses, :commit_statuses_state_check,
check: "state IN ('pending', 'success', 'failure', 'error')"
)
end
end