Skip to content

Migration with field as {:array, {:array, :time}} fails since 3.13.0 #675

Closed
@davidjulien

Description

@davidjulien

Elixir version

1.18.3

Database and Version

PostgreSQL 15.13

Ecto Versions

3.13.0

Database Adapter and Versions (postgrex, myxql, etc)

postgrex 0.20.0

Current behavior

When running a transaction like

  def change do
    create table(...) do
      ...
      add :forbidden_times, {:array, {:array, :time}}
      
      timestamps()
    end

The migration fails:

10:20:37.992 [info] create table appointment_types
** (MatchError) no match of right hand side value: ["time", "(0)", []]
    (ecto_sql 3.13.0) lib/ecto/adapters/postgres/connection.ex:1764: Ecto.Adapters.Postgres.Connection.column_type/2
    (ecto_sql 3.13.0) lib/ecto/adapters/postgres/connection.ex:1764: Ecto.Adapters.Postgres.Connection.column_type/2
    (ecto_sql 3.13.0) lib/ecto/adapters/postgres/connection.ex:1512: Ecto.Adapters.Postgres.Connection.column_definition/2
    (elixir 1.18.3) lib/enum.ex:4500: Enum.map_intersperse_list/3
    (elixir 1.18.3) lib/enum.ex:4500: Enum.map_intersperse_list/3
    (ecto_sql 3.13.0) lib/ecto/adapters/postgres/connection.ex:1268: Ecto.Adapters.Postgres.Connection.execute_ddl/1
    (ecto_sql 3.13.0) lib/ecto/adapters/sql.ex:1217: Ecto.Adapters.SQL.execute_ddl/4
    (ecto_sql 3.13.0) lib/ecto/migration/runner.ex:348: Ecto.Migration.Runner.log_and_execute_ddl/3

The bug may be here :

defp column_type({:array, type}, opts) do
[type, opts] = column_type(type, opts)
[type, "[]", opts]
end
defp column_type(type, opts) when type in ~w(time utc_datetime naive_datetime)a do
generated = Keyword.get(opts, :generated)
[ecto_to_db(type), "(0)", generated_expr(generated)]
end

At line 1764, the lib excepts an array of 2 values, but at line 1770, it returns an array of 3 values.

Expected behavior

array of array of time should be handled as before version 3.13.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions