Skip to content

Commit

Permalink
Raise when defining a bitstring field without a size with mysql
Browse files Browse the repository at this point in the history
  • Loading branch information
Gigitsu committed Feb 19, 2024
1 parent d979882 commit 2578a12
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/ecto/adapters/myxql/connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1462,6 +1462,7 @@ if Code.ensure_loaded?(MyXQL) do
defp ecto_cast_to_db(type, query), do: ecto_to_db(type, query)

defp ecto_size_to_db(:binary), do: "varbinary"
defp ecto_size_to_db(:bitstring), do: "bit"
defp ecto_size_to_db(type), do: ecto_to_db(type)

defp ecto_to_db(type, query \\ nil)
Expand All @@ -1471,7 +1472,6 @@ if Code.ensure_loaded?(MyXQL) do
defp ecto_to_db(:bigserial, _query), do: "bigint unsigned not null auto_increment"
defp ecto_to_db(:binary_id, _query), do: "binary(16)"
defp ecto_to_db(:string, _query), do: "varchar"
defp ecto_to_db(:bitstring, _query), do: "bit"
defp ecto_to_db(:float, _query), do: "double"
defp ecto_to_db(:binary, _query), do: "blob"
# MySQL does not support uuid
Expand All @@ -1485,6 +1485,12 @@ if Code.ensure_loaded?(MyXQL) do
defp ecto_to_db(:naive_datetime_usec, _query), do: "datetime"
defp ecto_to_db(atom, _query) when is_atom(atom), do: Atom.to_string(atom)

defp ecto_to_db(:bitstring, _query) do
raise ArgumentError,
"type `bitstring` without the `:size` option is unsupported." <>
"The type can be used with an explicit size attribute (eg. `add my_field, :bitstring, size: 42`)"
end

defp ecto_to_db(type, _query) do
raise ArgumentError,
"unsupported type `#{inspect(type)}`. The type can either be an atom, a string " <>
Expand Down

0 comments on commit 2578a12

Please sign in to comment.