Skip to content

Commit 3827237

Browse files
committed
Clarify that index names can be a string or an atom
Definitely both work, I've tried it out to make sure. Not having it specified caused some confusion in my team and I think it can help to specify this. I did change the time spec, as I'm rather sure it also ends up in there as a string. I'm a bit surprised/confused that the docs default to atom usage as as best I can tell the index is used for instance here: (Postgres connection) ```elixir queries = [ [ "CREATE ", if_do(index.unique, "UNIQUE "), "INDEX ", if_do(index.concurrently, "CONCURRENTLY "), if_do(command == :create_if_not_exists, "IF NOT EXISTS "), quote_name(index.name), " ON ", more stuff ``` which ends up converting the atom back to a string: ```elixir defp quote_name(nil, name), do: quote_name(name) defp quote_name(prefix, name), do: [quote_name(prefix), ?., quote_name(name)] defp quote_name(name) when is_atom(name) do quote_name(Atom.to_string(name)) end more stuff ``` But yeah, I don't know as well - I was thinking maybe to use name as a string in the docs at least once to show it's possible but maybe that breaks with a desire for uniformity.
1 parent df6732a commit 3827237

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

lib/ecto/migration.ex

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ defmodule Ecto.Migration do
396396
@type t :: %__MODULE__{
397397
table: String.t(),
398398
prefix: String.t() | nil,
399-
name: atom,
399+
name: String.t() | atom,
400400
columns: [atom | String.t()],
401401
unique: boolean,
402402
concurrently: boolean,
@@ -779,7 +779,8 @@ defmodule Ecto.Migration do
779779
780780
## Options
781781
782-
* `:name` - the name of the index. Defaults to "#{table}_#{column}_index".
782+
* `:name` - the name of the index. Can be provided as a string or an atom.
783+
Defaults to "#{table}_#{column}_index".
783784
* `:prefix` - specify an optional prefix for the index.
784785
* `:unique` - indicates whether the index should be unique. Defaults to `false`.
785786
* `:comment` - adds a comment to the index.

0 commit comments

Comments
 (0)