857 B · text History b868907
defmodule GitGud.Repo.Migrations.AddCacheEntryParts do
  use Ecto.Migration

  def change do
    # One row per uploaded chunk of a pending cache entry. `actions/cache`
    # uploads several chunks at once, each with a `Content-Range`; every
    # chunk is stored as its own object and `finalize` assembles them in
    # `offset` order. Rows (and their objects) are gone once the entry is
    # finalized.
    create table(:cache_entry_parts) do
      add :cache_entry_id, references(:cache_entries, on_delete: :delete_all), null: false
      add :offset, :bigint, null: false
      add :size, :bigint, null: false
      add :storage_key, :text, null: false

      timestamps(type: :utc_datetime)
    end

    # A retried chunk replaces the earlier upload at the same offset.
    create unique_index(:cache_entry_parts, [:cache_entry_id, :offset])
  end
end