1.1 KiB · text History 4b6fe3b
defmodule OhMyExOhIrcd.Repo.Migrations.CreateImages do
  use Ecto.Migration

  def change do
    create table(:images) do
      add :channel_id, references(:channels, on_delete: :delete_all), null: false
      # Uploading account (nullable so a deleted user doesn't drop the image).
      add :user_id, references(:users, on_delete: :nilify_all)
      add :who, :string, null: false
      # On-disk + public URL name (unguessable, random). Unique.
      add :filename, :string, null: false
      add :content_type, :string, null: false
      add :byte_size, :integer, null: false
      add :title, :string
      # Pinned images are exempt from retention GC. Pins are attributed to a
      # user for the per-user pin-byte budget.
      add :pinned, :boolean, null: false, default: false
      add :pinned_by_user_id, references(:users, on_delete: :nilify_all)
      add :pinned_at, :utc_datetime

      timestamps(type: :utc_datetime)
    end

    create unique_index(:images, [:filename])
    create index(:images, [:channel_id, :inserted_at])
    create index(:images, [:pinned_by_user_id])
    create index(:images, [:pinned])
  end
end