How to run ecto.create for an Elixir app?

I followed the getting started steps, using fly launch to setup an existing app. I had to convert from my previous Distillery deploy to Elixir Releases, fixing issues along the way. I think I’ve sorted those all out now, but when I try to fly deploy, it fails because my database hasn’t been setup. Locally I’d just do a mix ecto.create, but I can’t find anything in the forum or docs about doing this in Fly.io. Was this supposed to happen at some point during fly launch, but was interrupted by my build failures? I’ve tried re-running fly launch, but I still fail on my migratation step.

Here’s my full error:

Starting init (commit: 252b7bd)...
         Preparing to run: `/app/bin/migrate` as nobody
         2022/05/03 18:47:51 listening on [fdaa:0:607f:a7b:6b:efa4:7c00:2]:22 (DNS: [fdaa::3]:53)
         18:47:53.781 mfa=DBConnection.Connection.connect/2 [error] Postgrex.Protocol (#PID<0.163.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (104.198.233.116:5432): non-existing domain - :nxdomain
         18:47:53.781 mfa=DBConnection.Connection.connect/2 [error] Postgrex.Protocol (#PID<0.163.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (104.198.233.116:5432): non-existing domain - :nxdomain
         18:47:54.961 mfa=DBConnection.Connection.connect/2 [error] Postgrex.Protocol (#PID<0.162.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (104.198.233.116:5432): non-existing domain - :nxdomain
         18:47:55.443 mfa=DBConnection.Connection.connect/2 [error] Postgrex.Protocol (#PID<0.163.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (104.198.233.116:5432): non-existing domain - :nxdomain
         18:47:56.341 mfa=DBConnection.Connection.connect/2 [error] Postgrex.Protocol (#PID<0.162.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (104.198.233.116:5432): non-existing domain - :nxdomain
         18:47:56.734 mfa=Ecto.Migrator.verbose_schema_migration/3 [error] Could not create schema migrations table. This error usually happens due to the following:
           * The database does not exist
           * The "schema_migrations" table, which Ecto uses for managing
             migrations, was defined by another library
           * There is a deadlock while migrating (such as using concurrent
             indexes with a migration_lock)
         To fix the first issue, run "mix ecto.create".
         To address the second, you can run "mix ecto.drop" followed by
         "mix ecto.create". Alternatively you may configure Ecto to use
         another table and/or repository for managing migrations:

non-existing domain - :nxdomain usually means that IPv6 needs to be enabled.
In order to enable that you will need to make your repo config something like this

config :app, App.Repo,
    ssl: false,
    socket_options: [:inet6],
    url: database_url,
    pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10")

Ah got it- I was looking too far down in the logs.

I think I have all that configured correctly:

# runtime.exs
  config :ido, Ido.Repo,
    url: System.fetch_env!("DATABASE_URL"),
    pool_size: String.to_integer(System.get_env("POOL_SIZE", "10"))
# staging.exs
config :ido, Ido.Repo,
  adapter: Ecto.Adapters.Postgres,
  ssl: false,
  socket_options: [:inet6]

But I’m still getting the same error. I double-checked the logs, and it’s loading the right config (staging). Are there other settings I could be missing that would affect the domain?

Thanks!

We actually have a doc with some super useful information on this. Can you check that you’ve got everything set up per the doc?

I didn’t follow that guide, as it says it’s for versions of Phoenix before 1.6.3. I’m running 1.6.7. I followed this guide. Everything builds and runs locally, as well as on another hosting provider.