defmodule GitGud.Repo.Migrations.CreateWorkflows do
use Ecto.Migration
def change do
# Registered CI runners. A runner POSTs a registration token, gets
# back a long-lived token (hashed in `token_hash`), then exchanges
# it for ephemeral JWTs to pull jobs.
create table(:runners) do
add :owner_id, references(:users, on_delete: :delete_all)
add :name, :string, null: false
add :version, :string
add :labels, :map, null: false, default: %{"labels" => ["ubuntu-latest"]}
add :token_hash, :binary, null: false
add :last_seen_at, :utc_datetime
# active | offline | disabled
add :status, :string, null: false, default: "active"
timestamps(type: :utc_datetime)
end
create unique_index(:runners, [:token_hash])
create index(:runners, [:owner_id])
create table(:workflow_runs) do
add :repository_id, references(:repositories, on_delete: :delete_all), null: false
add :number, :integer, null: false
# path of the workflow file relative to the repo, e.g. ".github/workflows/ci.yml"
add :workflow_path, :string, null: false, size: 500
add :workflow_name, :string, size: 200
# push | pull_request | manual
add :trigger, :string, null: false
add :head_sha, :binary, null: false
add :head_ref, :string
# queued | running | success | failure | cancelled
add :status, :string, null: false, default: "queued"
add :conclusion, :string
add :started_at, :utc_datetime
add :completed_at, :utc_datetime
# The parsed workflow yaml as JSON, snapshot at run time.
add :workflow_doc, :map
timestamps(type: :utc_datetime)
end
create unique_index(:workflow_runs, [:repository_id, :number])
create index(:workflow_runs, [:repository_id, :status])
create index(:workflow_runs, [:head_sha])
create table(:workflow_jobs) do
add :workflow_run_id, references(:workflow_runs, on_delete: :delete_all), null: false
# key in the YAML `jobs:` map, e.g. "build"
add :job_id, :string, null: false, size: 200
add :name, :string, size: 200
add :runs_on, :map
add :needs, {:array, :string}, default: []
add :status, :string, null: false, default: "queued"
add :conclusion, :string
add :started_at, :utc_datetime
add :completed_at, :utc_datetime
add :runner_id, references(:runners, on_delete: :nilify_all)
# full job definition snapshot from YAML
add :definition, :map, null: false, default: %{}
timestamps(type: :utc_datetime)
end
create unique_index(:workflow_jobs, [:workflow_run_id, :job_id])
create index(:workflow_jobs, [:status])
create table(:workflow_steps) do
add :workflow_job_id, references(:workflow_jobs, on_delete: :delete_all), null: false
# 1-based position in the job's `steps:` array
add :number, :integer, null: false
add :name, :string, size: 250
add :status, :string, null: false, default: "pending"
add :conclusion, :string
add :started_at, :utc_datetime
add :completed_at, :utc_datetime
timestamps(type: :utc_datetime)
end
create unique_index(:workflow_steps, [:workflow_job_id, :number])
# Log chunks. Each row is a contiguous slice of step output; the UI
# tails by polling `seq > last_seen`.
create table(:workflow_step_logs, primary_key: false) do
add :workflow_step_id, references(:workflow_steps, on_delete: :delete_all),
null: false,
primary_key: true
add :seq, :integer, null: false, primary_key: true
add :body, :text, null: false
add :inserted_at, :utc_datetime, null: false, default: fragment("now()")
end
create table(:workflow_artifacts) do
add :workflow_run_id, references(:workflow_runs, on_delete: :delete_all), null: false
add :name, :string, null: false
add :size, :bigint, null: false, default: 0
add :content_type, :string
# S3/Garage object key.
add :storage_key, :string, null: false
timestamps(type: :utc_datetime)
end
create index(:workflow_artifacts, [:workflow_run_id])
end
end
4.1 KiB · text
5af55d9