bitwalker / timex_ecto

An adapter for using Timex DateTimes with Ecto
MIT License
162 stars 68 forks source link

tzdata error when ecto.migrate contains repo insert #41

Closed airlanggacahya closed 7 years ago

airlanggacahya commented 7 years ago

Error tzdata when running ecto.migrate that contains insertion command.

$ mix ecto.migrate
Compiling 9 files (.ex)

01:15:52.754 [info]  == Running WebApp.Repo.Migrations.InsertDefaultData.up/0 forward
** (ArgumentError) argument error
    (stdlib) :ets.lookup(:tzdata_current_release, :release_version)
    lib/tzdata/release_reader.ex:41: Tzdata.ReleaseReader.current_release_from_table/0
    lib/tzdata/release_reader.ex:13: Tzdata.ReleaseReader.simple_lookup/1
    lib/tzdata/release_reader.ex:7: Tzdata.ReleaseReader.zone_and_link_list/0
    lib/tzdata.ex:61: Tzdata.zone_exists?/1
    lib/timezone/timezone.ex:114: Timex.Timezone.name_of/1
    lib/timezone/timezone.ex:153: Timex.Timezone.do_get/3
    lib/timezone/timezone.ex:337: Timex.Timezone.convert/2
    lib/types/datetime.ex:132: Timex.Ecto.DateTime.dump/1
    (ecto) lib/ecto/type.ex:629: Ecto.Type.do_adapter_dump/3
    (ecto) lib/ecto/repo/schema.ex:619: Ecto.Repo.Schema.dump_field!/6
    (ecto) lib/ecto/repo/schema.ex:632: anonymous fn/6 in Ecto.Repo.Schema.dump_fields!/5
    (elixir) lib/enum.ex:1623: Enum."-reduce/3-lists^foldl/2-0-"/3
    (ecto) lib/ecto/repo/schema.ex:630: Ecto.Repo.Schema.dump_fields!/5
    (ecto) lib/ecto/repo/schema.ex:580: Ecto.Repo.Schema.dump_changes!/6
    (ecto) lib/ecto/repo/schema.ex:184: anonymous fn/11 in Ecto.Repo.Schema.do_insert/4
    (ecto) lib/ecto/repo/schema.ex:608: anonymous fn/3 in Ecto.Repo.Schema.wrap_in_transaction/6
    (db_connection) lib/db_connection.ex:1154: DBConnection.transaction_nested/2
    (db_connection) lib/db_connection.ex:1014: DBConnection.transaction_meter/3
    (db_connection) lib/db_connection.ex:667: DBConnection.transaction/3

Model

  schema "categories" do
    field :build_datetime, Timex.Ecto.DateTime
  end

Migration File

{:ok, _} = Repo.insert %Category{
      build_datetime: nil
    }

Temporary solution, add Application.ensure_all_started :timex before migration code. But it seems hacky....

bitwalker commented 7 years ago

Is timex in your applications list in mix.exs? If not, adding it there should fix it. It was my understanding that ecto.migrate starts the application before running migrations, so if timex is in the applications list, it should work as expected. If that's not the case, then your solution is the only way around that I'm afraid.