尝试将Heroku CI与Phoenix和heroku buildpack灵丹妙药一起使用。
测试正在运行,但收到错误消息
psql: FATAL: database "u13792" does not exist
或
role "postgres" does not exist
。
{
"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
...
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
...
...
# Configure your database
config :api, Api.Repo,
username: "postgres",
password: "postgres",
database: "api_test",
hostname: "localhost",
pool: Ecto.Adapters.SQL.Sandbox
...
当我从app.json中删除psql -c 'CREATE ROLE postgres;
命令时,出现以下错误:
-----> 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
谢谢。
答案 0 :(得分:0)
好吧,显然,config.test.ex需要一个DATABASE_URL变量。
对于追随我的任何人来说,不需要dyno。
因此app.json看起来可能像这样:
...
},
"stack": "heroku-18",
"environments": {
"test": {
"env": {
"MIX_ENV": "test"
}
}
}
}
最重要的是,配置测试数据库配置需要DATABASE_URL。
...
config :api, Api.Repo,
adapter: Ecto.Adapters.Postgres,
url: System.get_env("DATABASE_URL"),
pool: Ecto.Adapters.SQL.Sandbox
...
这些资源帮助了:
Blog Post
Heroku Example App