865 B · text History b868907
defmodule GitGud.Repo.Migrations.CreateInstanceSettings do
  use Ecto.Migration

  @moduledoc """
  Instance-wide levers an admin can turn without a deploy.

  One row per setting rather than one row with a column per setting:
  adding a lever is then an insert, not a migration, and the admin UI
  can render the set it knows about without caring what else is stored.
  """

  def change do
    create table(:instance_settings) do
      add :key, :string, null: false
      # Wrapped in a map so a scalar can be stored without inventing a
      # column per type, and so a setting can grow structure later
      # without a migration.
      add :value, :map, null: false, default: %{}
      add :updated_by_id, references(:users, on_delete: :nilify_all)

      timestamps(type: :utc_datetime)
    end

    create unique_index(:instance_settings, [:key])
  end
end