   end
 
 
-  # Deletes one gate from the Flag's Redis hash.
+  # Deletes one gate from the toggles table in the DB.
   # Deleting gates is idempotent and deleting unknown gates is safe.
   # A flag will continue to exist even though it has no gates.
   #

      where: r.flag_name == ^flag_name
    )

    {count, something} = repo().delete_all(query)
    {:ok, flag} = get(flag_name)

    publish_change(flag_name)

    {:ok, flag}
    # {:error, "reason"}
  end




  def get(flag_name) do
    name_string = to_string(flag_name)
    query = from(r in Record, where: r.flag_name == ^name_string)
    try do
      results = repo().all(query)
      flag = deserialize(flag_name, results)
      {:ok, flag}
    rescue
      e in [Ecto.QueryError] -> {:error, e}
    end
  end


  def put(flag_name, gate = %Gate{}) do
    changeset = Record.build(flag_name, gate)
    options = [
      on_conflict: [set: [enabled: gate.enabled]],
      conflict_target: [:flag_name, :gate_type, :target] # the unique index
    ]

    case repo().insert(changeset, options) do
      {:ok, _struct} ->
        {:ok, flag} = get(flag_name)
        publish_change(flag_name)
