Heroku CI, Phoenix, Elixir: «роль« postgres »не существует» «psql: FATAL: база данных« u13792 »не существует» - PullRequest
0 голосов
/ 09 февраля 2019

Попытка использовать Heroku CI с Фениксом и героем buildpack.

Тесты запущены, но появляется сообщение об ошибке psql: FATAL: database "u13792" does not exist или role "postgres" does not exist.

app.json

{
  "addons": [
    "heroku-postgresql"
  ],
  "buildpacks": [
    {
      "url": "https://github.com/HashNuke/heroku-buildpack-elixir.git"
    }
  ],
  "env": {
    "ACCEPT_ORIGIN": {
      "required": true
    },
    "POOL_SIZE": {
      "required": true
    },
    "SECRET_KEY_BASE": {
      "required": true
    }
  },
  "formation": {
    "web": {
      "quantity": 1
    }
  },
  "name": "valius-api",
  "scripts": {
  },
  "stack": "heroku-18",
  "environments": {
    "test": {
      "env": {
        "MIX_ENV": "test"
      },
      "addons": ["heroku-postgresql:in-dyno"],
      "scripts": {
        "test-setup": "psql -c 'CREATE ROLE postgres;'"
      }
    }
  }
}

Консоль тестирования:

  lib/mix/tasks/ja_serializer.gen.phoenix_api.ex:57

  lib/mix/tasks/ja_serializer.gen.phoenix_api.ex:60

warning: function Mix.Phoenix.params/1 is undefined or private

  lib/mix/tasks/ja_serializer.gen.phoenix_api.ex:44

Generated ja_serializer app

==> phoenix_ecto

Compiling 6 files (.ex)

Generated phoenix_ecto app

==> api

Compiling 21 files (.ex)

Generated api app

-----> Creating .profile.d with env vars

-----> Writing export for multi-buildpack support

-----> Running test-setup command `psql -c 'CREATE ROLE postgres;'`...

psql: FATAL:  database "u13792" does not exist

-----> test-setup command `psql -c 'CREATE ROLE postgres;'` failed with exit status 2

mix.exs

...
  defp aliases do
    [
      "ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"],
      "ecto.reset": ["ecto.drop", "ecto.setup"],
      test: ["ecto.migrate", "test"],
      "test.local": ["ecto.create --quiet", "ecto.migrate", "test"]
    ]
  end
...

config / test.ex

...
# Configure your database
config :api, Api.Repo,
  username: "postgres",
  password: "postgres",
  database: "api_test",
  hostname: "localhost",
  pool: Ecto.Adapters.SQL.Sandbox

...

Когда я удаляю команду psql -c 'CREATE ROLE postgres; из app.json, она выдает следующие ошибки:

Тестовая консоль без CREATE ROLE

-----> The postgresql buildpack does not run tests. Skipping.

-----> Running Elixir buildpack tests...

21:24:33.873 [error] Postgrex.Protocol (#PID<0.245.0>) failed to connect: ** (Postgrex.Error) FATAL 28000 (invalid_authorization_specification) role "postgres" does not exist

21:24:33.873 [error] Postgrex.Protocol (#PID<0.246.0>) failed to connect: ** (Postgrex.Error) FATAL 28000 (invalid_authorization_specification) role "postgres" does not exist

21:24:35.752 [error] Postgrex.Protocol (#PID<0.245.0>) failed to connect: ** (Postgrex.Error) FATAL 28000 (invalid_authorization_specification) role "postgres" does not exist

21:24:36.124 [error] Postgrex.Protocol (#PID<0.246.0>) failed to connect: ** (Postgrex.Error) FATAL 28000 (invalid_authorization_specification) role "postgres" does not exist

** (DBConnection.ConnectionError) connection not available and request was dropped from queue after 2984ms. You can configure how long requests wait in the queue using :queue_target and :queue_interval. See DBConnection.start_link/2 for more information

    (db_connection) lib/db_connection/ownership.ex:81: DBConnection.Ownership.ownership_checkout/2

    (ecto_sql) lib/ecto/adapters/sql/sandbox.ex:431: Ecto.Adapters.SQL.Sandbox.checkout/2

    (ecto_sql) lib/ecto/adapters/sql/sandbox.ex:478: Ecto.Adapters.SQL.Sandbox.unboxed_run/2

    (ecto_sql) lib/mix/tasks/ecto.migrate.ex:108: anonymous fn/4 in Mix.Tasks.Ecto.Migrate.run/2

    (elixir) lib/enum.ex:765: Enum."-each/2-lists^foreach/1-0-"/2

    (elixir) lib/enum.ex:765: Enum.each/2

    (mix) lib/mix/task.ex:316: Mix.Task.run_task/3

    (mix) lib/mix/task.ex:350: Mix.Task.run_alias/3

-----> Elixir buildpack tests failed with exit status 1

Спасибо.

1 Ответ

0 голосов
/ 09 февраля 2019

ОК, очевидно, для config.test.ex требовалась переменная DATABASE_URL.
Для тех, кто следовал за мной, в in-dyno не было необходимости.
Так что app.json может выглядеть так:

app.json

...
  },
  "stack": "heroku-18",
  "environments": {
    "test": {
      "env": {
        "MIX_ENV": "test"
      }
    }
  }
}

И самое главное, для конфигурации базы данных теста конфигурации требуется DATABASE_URL.

config.test.ex

...
config :api, Api.Repo,
  adapter: Ecto.Adapters.Postgres,
  url: System.get_env("DATABASE_URL"),
  pool: Ecto.Adapters.SQL.Sandbox
...

Эти ресурсы помогли:
Запись блога
Пример приложения Heroku

...