1.2 KiB · text History 6280797
defmodule GitGud.Repo.Migrations.CreateEvents do
use Ecto.Migration
# An append-only log of what happened to an issue or pull request:
# pushes, title edits, state flips, labels, moderation. Polymorphic
# over `target_type` the same way `labelings` is, rather than one
# table per target — the history pages read them identically and the
# alternative is two schemas that differ only in a foreign key.
#
# `actor_id` is nullable on purpose: pushes are recorded by a worker
# with no user attached, and federated actions arrive from a remote
# actor rather than a local one.
def change do
create table(:events) do
add :target_type, :string, null: false
add :target_id, :bigint, null: false
add :kind, :string, null: false
# Per-kind payload — old/new titles, sha pair, label name, etc.
# Shapes are documented on GitGud.Events.
add :data, :map, null: false, default: %{}
add :actor_id, references(:users, on_delete: :nilify_all)
timestamps(type: :utc_datetime, updated_at: false)
end
# The only read: one target's history, oldest first.
create index(:events, [:target_type, :target_id, :inserted_at])
end
end