Current section

65 Versions

Jump to

Compare versions

6 files changed
+36 additions
-19 deletions
  @@ -1,5 +1,12 @@
1 1 # Changelog for v3.x
2 2
3 + ## v3.4.2 (2020-04-02)
4 +
5 + ### Bug fixes
6 +
7 + * [myxql] A binary with size should be a varbinary
8 + * [mssql] A binary without size should be a varbinary(max)
9 +
3 10 ## v3.4.1 (2020-03-25)
4 11
5 12 ### Bug fixes
  @@ -72,4 +72,4 @@
72 72 {<<"optional">>,true},
73 73 {<<"repository">>,<<"hexpm">>},
74 74 {<<"requirement">>,<<"~> 2.1.0">>}]]}.
75 - {<<"version">>,<<"3.4.1">>}.
75 + {<<"version">>,<<"3.4.2">>}.
  @@ -874,13 +874,12 @@ if Code.ensure_loaded?(MyXQL) do
874 874 size = Keyword.get(opts, :size)
875 875 precision = Keyword.get(opts, :precision)
876 876 scale = Keyword.get(opts, :scale)
877 - type_name = ecto_to_db(type)
878 877
879 878 cond do
880 - size -> [type_name, ?(, to_string(size), ?)]
881 - precision -> [type_name, ?(, to_string(precision), ?,, to_string(scale || 0), ?)]
882 - type == :string -> [type_name, "(255)"]
883 - true -> type_name
879 + size -> [ecto_size_to_db(type), ?(, to_string(size), ?)]
880 + precision -> [ecto_to_db(type), ?(, to_string(precision), ?,, to_string(scale || 0), ?)]
881 + type == :string -> ["varchar(255)"]
882 + true -> ecto_to_db(type)
884 883 end
885 884 end
886 885
  @@ -995,6 +994,9 @@ if Code.ensure_loaded?(MyXQL) do
995 994 defp ecto_cast_to_db(:naive_datetime_usec, _query), do: "datetime(6)"
996 995 defp ecto_cast_to_db(type, query), do: ecto_to_db(type, query)
997 996
997 + defp ecto_size_to_db(:binary), do: "varbinary"
998 + defp ecto_size_to_db(type), do: ecto_to_db(type)
999 +
998 1000 defp ecto_to_db(type, query \\ nil)
999 1001 defp ecto_to_db({:array, _}, query), do: error!(query, "Array type is not supported by MySQL")
1000 1002 defp ecto_to_db(:id, _query), do: "integer"
  @@ -1504,16 +1504,13 @@ if Code.ensure_loaded?(Tds) do
1504 1504 defp ecto_to_db(:string, s, _, _, _) when s in 1..4_000, do: "nvarchar(#{s})"
1505 1505 defp ecto_to_db(:float, nil, _, _, _), do: "float"
1506 1506 defp ecto_to_db(:float, s, _, _, _) when s in 1..53, do: "float(#{s})"
1507 - defp ecto_to_db(:binary, nil, _, _, _), do: "varbinary(2000)"
1508 - defp ecto_to_db(:binary, :max, _, _, _), do: "varbinary(max)"
1507 + defp ecto_to_db(:binary, nil, _, _, _), do: "varbinary(max)"
1509 1508 defp ecto_to_db(:binary, s, _, _, _) when s in 1..8_000, do: "varbinary(#{s})"
1510 1509 defp ecto_to_db(:uuid, _, _, _, _), do: "uniqueidentifier"
1511 - defp ecto_to_db(:map, nil, _, _, _), do: "nvarchar(2000)"
1512 - defp ecto_to_db(:map, :max, _, _, _), do: "nvarchar(max)"
1510 + defp ecto_to_db(:map, nil, _, _, _), do: "nvarchar(max)"
1513 1511 defp ecto_to_db(:map, s, _, _, _) when s in 0..4_000, do: "nvarchar(#{s})"
1514 - defp ecto_to_db({:map, _}, nil, _, _, _), do: "nvarchar(2000)"
1512 + defp ecto_to_db({:map, _}, nil, _, _, _), do: "nvarchar(max)"
1515 1513 defp ecto_to_db({:map, _}, s, _, _, _) when s in 1..4_000, do: "nvarchar(#{s})"
1516 - defp ecto_to_db({:map, _}, :max, _, _, _), do: "nvarchar(max)"
1517 1514 defp ecto_to_db(:time, _, _, _, _), do: "time(0)"
1518 1515 defp ecto_to_db(:time_usec, _, p, _, _) when p in 0..7, do: "time(#{p})"
1519 1516 defp ecto_to_db(:time_usec, _, _, _, _), do: "time(6)"
  @@ -69,7 +69,7 @@ defmodule Ecto.Migration do
69 69
70 70 $ mix ecto.migrate
71 71
72 - You can also it rollback by calling
72 + You can also roll it back by calling:
73 73
74 74 $ mix ecto.rollback --step 1
75 75
  @@ -134,13 +134,24 @@ defmodule Ecto.Migration do
134 134 ## Field Types
135 135
136 136 The Ecto primitive types are mapped to the appropriate database
137 - type by the various database adapters. For example, `:string` is converted to
138 - `:varchar`, `:binary` to `:bits` or `:blob`, and so on.
137 + type by the various database adapters. For example, `:string` is
138 + converted to `:varchar`, `:binary` to `:bytea` or `:blob`, and so on.
139 139
140 140 Similarly, you can pass any field type supported by your database
141 - as long as it maps to an Ecto type. For instance, you can use `:text`,
142 - `:varchar`, or `:char` in your migrations as `add :field_name, :text`.
143 - In your Ecto schema, they will all map to the same `:string` type.
141 + as long as it maps to an Ecto type. For instance, for an Ecto schema
142 + with the field `:string`, the database migration type can be any of
143 + `:text`, `:char` or `:varchar` (the default).
144 +
145 + In particular, note that:
146 +
147 + * the `:string` type in migrations by default has a limit of 255 characters.
148 + If you need more or less characters, pass the `:size` option, such
149 + as `add :field, :string, size: 10`. If you don't want to impose a limit,
150 + most databases support a `:text` type or similar
151 +
152 + * the `:binary` type in migrations by default has no size limit. If you want
153 + to impose a limit, pass the `:size` option accordingly. In MySQL, passing
154 + the size option changes the underlying field from "blob" to "varbinary"
144 155
145 156 Remember, atoms can contain arbitrary characters by enclosing in
146 157 double quotes the characters following the colon. So, if you want to use a
Loading more files…