defmodule GitGud.Repo.Migrations.CreateCacheEntries do
use Ecto.Migration
def change do
create table(:cache_entries) do
add :repository_id, references(:repositories, on_delete: :delete_all), null: false
# The opaque cache key set by `actions/cache`. May be a literal or
# a hash-derived string. Bounded to 512 chars by the action.
add :key, :string, null: false, size: 600
# `version` is a hash of the cached *paths*, so two cache actions
# with the same `key` but different paths don't collide.
add :version, :string, null: false, size: 128
# Ref the cache was uploaded for ("refs/heads/main" etc). Lookup
# honors the current ref first, then falls back to the repo's
# default branch, matching GitHub's scope-isolation semantics.
# NULL means "global to the repo" — accepts lookups from any ref.
add :ref, :string, size: 250
add :storage_key, :text, null: false
# Bytes — populated by `finalize`. Pending uploads (reserved but
# not finalized) have nil here.
add :size, :bigint
# When the upload completed. Lookups gate on this being non-null
# so half-uploaded rows aren't returned as hits.
add :archived_at, :utc_datetime
# Used by the eviction worker (next slice).
add :last_used_at, :utc_datetime
timestamps(type: :utc_datetime)
end
# The same (repo, key, version, ref) re-uploads as a single row —
# the row's storage_key is replaced + archived_at refreshes.
# NULL ref is its own scope (PG treats NULL distinctly in unique
# indexes by default; we accept that).
create unique_index(:cache_entries, [:repository_id, :key, :version, :ref],
name: :cache_entries_scope_index
)
# Hot path: prefix-key lookups within (repo, version).
create index(:cache_entries, [:repository_id, :version])
end
end
1.9 KiB · text
5af55d9