You’d only use the socket option if you were running the code on the same machine as the database, which isn’t the case here.
The example on that linked Github doc that uses ports like the ci.yml in your repo does is the “running jobs directly on the worker machine” which sets POSTGRES_HOST to localhost and relies on Docker’s port forwarding to connect the containers.
services:
postgres:
image: postgres
env:
POSTGRES_PASSWORD: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
# Maps tcp port 5432 on service container to the host
- 5432:5432
and added these lines:
POSTGRES_HOST: localhost
# The default PostgreSQL port
POSTGRES_PORT: 5432
With these changes, I could pass the migration part, but in the test section I got error from database
Error: 2.017 [error] GenServer #PID<0.246.0> terminating
** (RuntimeError) connect raised ArgumentError exception. The exception details are hidden, as they may contain sensitive data such as database credentials. You may set :show_sensitive_data_on_connection_error to true when starting your connection if you wish to see all of the details
(postgrex 0.15.13) lib/postgrex/protocol.ex:139: Postgrex.Protocol.endpoints/1
(postgrex 0.15.13) lib/postgrex/protocol.ex:66: Postgrex.Protocol.connect/1
(db_connection 2.4.1) lib/db_connection/connection.ex:82: DBConnection.Connection.connect/2
(connection 1.1.0) lib/connection.ex:622: Connection.enter_connect/5
(stdlib 3.17) proc_lib.erl:226: :proc_lib.init_p_do_apply/3
Last message: nil
State: Postgrex.Protocol
I added show_sensitive_data_on_connection_error: true to see more information
Error: 0.104 [error] GenServer #PID<0.247.0> terminating
** (ArgumentError) expected :hostname, endpoints, :socket_dir, or :socket to be given
(postgrex 0.15.13) lib/postgrex/protocol.ex:139: Postgrex.Protocol.endpoints/1
(postgrex 0.15.13) lib/postgrex/protocol.ex:66: Postgrex.Protocol.connect/1
(db_connection 2.4.1) lib/db_connection/connection.ex:82: DBConnection.Connection.connect/2
(connection 1.1.0) lib/connection.ex:622: Connection.enter_connect/5
(stdlib 3.17) proc_lib.erl:226: :proc_lib.init_p_do_apply/3
Last message: nil
State: Postgrex.Protocol
All lines of my CI:
I created a simple elixir application you can access to it (click please) and see all the CI code
name: MishkaCms CI
on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
test:
name: Run tests
runs-on: ubuntu-latest
env:
MIX_ENV: test
strategy:
matrix:
otp: ['24.x']
elixir: ['1.13.2']
postgres: ['14.1-alpine']
services:
postgres:
image: postgres
env:
POSTGRES_PASSWORD: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
# Maps tcp port 5432 on service container to the host
- 5432:5432
steps:
- uses: actions/checkout@v2
- uses: erlef/setup-beam@v1.10.0
with:
otp-version: ${{matrix.otp}}
elixir-version: ${{matrix.elixir}}
- name: Elixir and Erlang Dependencies
run: |
mix local.hex --force
mix local.rebar --force
mix archive.install hex phx_new --force
- name: Source Compiling
run: |
mix deps.get
mix deps.compile
- name: Database Dependencies
env:
POSTGRES_HOST: localhost
# The default PostgreSQL port
POSTGRES_PORT: 5432
DATABASE_USER: postgres
DATABASE_PASSWORD: postgres
DATABASE_HOST: localhost
run: |
mix ecto.create
mix ecto.migrate
- name: Run tests
run: mix test
I do not know how to fix this, I tried many ways please help me to figure out
Hello, I fixed all the pervious errors, In testing I have a problem that it shows me undefined_table, but this table exists and I have no problem in my local and server with these packages.
Hence, I tried to drop and migrate again, but it always shows me
09:36:35.700 [info] Migrations already up
09:36:35.779 [info] Migrations already up
I have written these line before, and I have dropped the dB before migration
Please help me to fix this
Thank you
Update
I fixed it with some changes in my config and deleting MIX_ENV=test