2
votes

I have a "dummy" app in my mix app, so, it's first migration is placed in test/dummy/priv/repo/migrations/20160323060044_create_user.exs.

I want to run this migration, but it returns 11:19:20.647 [info] Already up, and this disappoints me.

Here is my test.exs:

config :ecto_state_machine, Dummy.Repo,
  adapter: Ecto.Adapters.Postgres,
  username: System.get_env("USER"),
  password: "posgtres",
  database: "ecto_state_machine_test",
  pool_size: 10,
  port: 5432,
  priv: "test/dummy/priv/repo/"

Here is my migration:

defmodule Dummy.Repo.Migrations.CreateUser do
  use Ecto.Migration

  def change do
    create table(:users) do
      add :state, :string, null: false
      add :confirmed_at, :datetime

      timestamps
    end
  end
end

I'm running

MIX_ENV=test mix ecto.migrate -r Dummy.Repo

and get annoying already up instead of migration. What's I'm doing wrong?

My attempts:

  1. I tried to drop and re-create database, nothing happened

  2. My another turn was to require the code. I tried to implement this in my test.exs or dev.exs, but I received `module Ecto.Migration is not loaded and could not be found

    "test/dummy/priv/repo/migrations" |> Path.join("**/*.exs") |> Path.wildcard |> Enum.map(&Code.require_file/1)

  3. I also tried to create a fake migration by MIX_ENV=test mix ecto.gen.migration f -r Dummy.Repo, fill it with code which raise an exception, and than I had

    MIX_ENV=test mix ecto.migrate -r Dummy.Repo # => 12:49:00.932 [info] Already up

So, it can't find a repo. Sad, but true

  1. I also tried to load shell MIX_ENV=test, then invoke code from 2nd approach, then Mix.Task.run "ecto.migrate" ["-r", "Dummy.Repo"]. it returned :noop to me?

  2. Github issue: https://github.com/elixir-lang/ecto/issues/1428

1
Have you created your migration using mix ecto.gen.migration create_user? This should always place the transaction where Ecto can read it.tkowal
Yes, I did it. Take a look at 3rd approachasiniy
Wow, I've been dealing with this for hours and hours. When I finally narrowed it down to the priv aspect (and consequently the troubleshooting was done), I finally came across your post of the exact same problem! If the ecto.gen.migration command works, then the ecto.migrate command should also work!user4275029

1 Answers

1
votes

Jose Valim commented at github:

This is fixed in Ecto 2.0.0-rc. In previous versions, migrations would always have to be inside priv. We have removed this requirement in Ecto 2.0.