3.4 KiB · text History 334594a
defmodule Vigil.Repo.Migrations.CreateDebugFiles do
  use Ecto.Migration

  # Slice 12 (ROADMAP.md): debug information files (sentry-cli
  # `debug-files upload`, `upload-proguard`), where their assembly stands,
  # and the raw minidumps native crashes arrive with.
  def change do
    # One object of an uploaded file, per project. A fat Mach-O holds
    # several objects: one row each, sharing the file (`storage_key`). A
    # Proguard mapping is one row, `debug_id` its UUID.
    create table(:debug_files, primary_key: false) do
      add :id, :binary_id, primary_key: true

      add :organization_id, references(:organizations, type: :binary_id, on_delete: :delete_all),
        null: false

      add :project_id, references(:projects, type: :binary_id, on_delete: :delete_all),
        null: false

      # SHA-1 of the whole file, as sentry-cli names it.
      add :checksum, :string, null: false
      # symbolic's form: lowercase UUID, `-<age>` when the age isn't 0.
      add :debug_id, :string, null: false
      add :code_id, :string
      # The name sentry-cli gave (the file's path, or `/proguard/<uuid>.txt`).
      add :object_name, :text, null: false
      # x86_64, arm64, ...; `any` for a Proguard mapping.
      add :cpu_name, :string, null: false
      # elf | macho | pe | pdb | portablepdb | breakpad | wasm | proguard ...
      add :file_format, :string, null: false
      # exe | lib | dbg | ...; nil for a Proguard mapping.
      add :kind, :string
      # symtab, debug, unwind, sources; mapping (Proguard).
      add :features, {:array, :string}, null: false, default: []
      add :size, :bigint, null: false
      add :storage_key, :string, null: false
      # The SymCache, once one has been built (lazily, at the first lookup).
      add :symcache_key, :string

      timestamps(type: :utc_datetime)
    end

    create unique_index(:debug_files, [:project_id, :checksum, :debug_id])
    create index(:debug_files, [:project_id, :debug_id])

    # Where a debug file's assemble stands, per (project, checksum):
    # created, assembling, ok, error. sentry-cli polls it (`--wait`).
    create table(:debug_file_assemblies, primary_key: false) do
      add :id, :binary_id, primary_key: true

      add :project_id, references(:projects, type: :binary_id, on_delete: :delete_all),
        null: false

      add :checksum, :string, null: false
      add :state, :string, null: false
      add :detail, :text

      timestamps(type: :utc_datetime)
    end

    create unique_index(:debug_file_assemblies, [:project_id, :checksum])

    # Files an event arrived with (so far: its minidump), bytes in
    # Vigil.Storage. Swept with the instance's event retention.
    create table(:event_attachments, primary_key: false) do
      add :id, :binary_id, primary_key: true

      add :organization_id, references(:organizations, type: :binary_id, on_delete: :delete_all),
        null: false

      add :project_id, references(:projects, type: :binary_id, on_delete: :delete_all),
        null: false

      add :event_id, :string, null: false
      add :name, :string, null: false
      add :attachment_type, :string, null: false
      add :size, :bigint, null: false
      add :storage_key, :string, null: false

      timestamps(type: :utc_datetime, updated_at: false)
    end

    create index(:event_attachments, [:project_id, :event_id])
    create index(:event_attachments, [:inserted_at])
  end
end