Skip to content

Commit

Permalink
Add migration support to binary types
Browse files Browse the repository at this point in the history
  • Loading branch information
Gigitsu committed Nov 25, 2023
1 parent 46c5721 commit dc174d5
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/ecto/adapters/myxql/connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1456,6 +1456,7 @@ 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: "varbinary"
defp ecto_to_db(:float, _query), do: "double"
defp ecto_to_db(:binary, _query), do: "blob"
# MySQL does not support uuid
Expand Down
1 change: 1 addition & 0 deletions lib/ecto/adapters/postgres/connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1856,6 +1856,7 @@ if Code.ensure_loaded?(Postgrex) do
defp ecto_to_db(:bigserial), do: "bigserial"
defp ecto_to_db(:binary_id), do: "uuid"
defp ecto_to_db(:string), do: "varchar"
defp ecto_to_db(:bitstring), do: "bit varying"
defp ecto_to_db(:binary), do: "bytea"
defp ecto_to_db(:map), do: Application.fetch_env!(:ecto_sql, :postgres_map_type)
defp ecto_to_db({:map, _}), do: Application.fetch_env!(:ecto_sql, :postgres_map_type)
Expand Down
6 changes: 4 additions & 2 deletions test/ecto/adapters/myxql_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -1623,7 +1623,8 @@ defmodule Ecto.Adapters.MyXQLTest do
{:add, :on_hand, :integer, [default: 0, null: true]},
{:add, :likes, :"smallint unsigned", [default: 0, null: false]},
{:add, :published_at, :"datetime(6)", [null: true]},
{:add, :is_active, :boolean, [default: true]}
{:add, :is_active, :boolean, [default: true]},
{:add, :token, :bitstring, [size: 23]}
]}

assert execute_ddl(create) == [
Expand All @@ -1634,7 +1635,8 @@ defmodule Ecto.Adapters.MyXQLTest do
`on_hand` integer DEFAULT 0 NULL,
`likes` smallint unsigned DEFAULT 0 NOT NULL,
`published_at` datetime(6) NULL,
`is_active` boolean DEFAULT true) ENGINE = INNODB
`is_active` boolean DEFAULT true,
`token` varbinary(23)) ENGINE = INNODB
"""
|> remove_newlines
]
Expand Down
2 changes: 2 additions & 0 deletions test/ecto/adapters/postgres_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2034,6 +2034,7 @@ defmodule Ecto.Adapters.PostgresTest do
{:add, :on_hand, :integer, [default: 0, null: true]},
{:add, :published_at, :"time without time zone", [null: true]},
{:add, :is_active, :boolean, [default: true]},
{:add, :token, :bitstring, [size: 23]},
{:add, :tags, {:array, :string}, [default: []]},
{:add, :languages, {:array, :string}, [default: ["pt", "es"]]},
{:add, :limits, {:array, :integer}, [default: [100, 30_000]]}
Expand All @@ -2046,6 +2047,7 @@ defmodule Ecto.Adapters.PostgresTest do
"on_hand" integer DEFAULT 0 NULL,
"published_at" time without time zone NULL,
"is_active" boolean DEFAULT true,
"token" bit varying(23),
"tags" varchar(255)[] DEFAULT ARRAY[]::varchar[],
"languages" varchar(255)[] DEFAULT ARRAY['pt','es']::varchar[],
"limits" integer[] DEFAULT ARRAY[100,30000]::integer[])
Expand Down

0 comments on commit dc174d5

Please sign in to comment.