Heroku CI、Phoenix、Elixir:'role "postgres" does not exist' 'psql: FATAL: database "u13792" does not exist'
Heroku CI, Phoenix, Elixir: 'role "postgres" does not exist' 'psql: FATAL: database "u13792" does not exist'
尝试将 Heroku CI 与 Phoenix 和 heroku buildpack elixir 一起使用。
测试 运行,但收到错误消息
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
...
当我从 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
谢谢。
好吧,显然,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
...
这些资源帮助了:
Blog Post
Heroku Example App
尝试将 Heroku CI 与 Phoenix 和 heroku buildpack elixir 一起使用。
测试 运行,但收到错误消息
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
...
当我从 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
谢谢。
好吧,显然,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
...
这些资源帮助了:
Blog Post
Heroku Example App