defmodule GitGud.Repo.Migrations.CreateReports do
use Ecto.Migration
def change do
create table(:reports) do
add :reporter_id, references(:users, on_delete: :nilify_all)
# Polymorphic: target_type ∈ {"issue", "issue_comment",
# "pull_request", "pr_comment", "actor", "inbox_delivery"}
add :target_type, :string, null: false, size: 30
add :target_id, :bigint, null: false
# spam | abuse | harassment | other
add :reason, :string, null: false, size: 30
add :details, :text
# open | dismissed | actioned
add :state, :string, null: false, default: "open"
add :resolution_notes, :text
add :resolved_by_id, references(:users, on_delete: :nilify_all)
add :resolved_at, :utc_datetime
timestamps(type: :utc_datetime)
end
create index(:reports, [:target_type, :target_id])
create index(:reports, [:state])
create index(:reports, [:reporter_id])
# Prevent the same reporter from filing two open reports against the
# same target — but allow re-reporting after resolution.
create unique_index(:reports, [:reporter_id, :target_type, :target_id],
where: "state = 'open'",
name: :reports_unique_open_per_reporter
)
end
end
1.2 KiB · text
5af55d9