Skip to content

Commit

Permalink
use postgres default ENV variable names everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
izelnakri committed Aug 30, 2024
1 parent 069076c commit 6cd5569
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 20 deletions.
7 changes: 3 additions & 4 deletions .env
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
REGISTRY="inakri" # set -a && source .env
REPO_OWNER="izelnakri"
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_HOST=localhost
PG_HOST=localhost
PGUSER=postgres
PGPASSWORD=postgres
PGHOST=localhost
MIX_ENV=test
# CIRCLE_BRANCH=$$(if [ -v CIRCLE_BRANCH ]; then echo master; else git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'; fi)
# DOCKER_TAG=paper_trail:master
Expand Down
21 changes: 12 additions & 9 deletions config/test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,29 @@ config :paper_trail, repo: PaperTrail.Repo, originator: [name: :user, model: Use

config :paper_trail, PaperTrail.Repo,
adapter: Ecto.Adapters.Postgres,
username: System.get_env("POSTGRES_USER"),
password: System.get_env("POSTGRES_PASSWORD"),
username: System.get_env("PGUSER"),
password: System.get_env("PGPASSWORD"),
database: "paper_trail_test",
hostname: System.get_env("PG_HOST"),
hostname: System.get_env("PGHOST"),
show_sensitive_data_on_connection_error: true,
poolsize: 10

config :paper_trail, PaperTrail.UUIDRepo,
adapter: Ecto.Adapters.Postgres,
username: System.get_env("POSTGRES_USER"),
password: System.get_env("POSTGRES_PASSWORD"),
username: System.get_env("PGUSER"),
password: System.get_env("PGPASSWORD"),
database: "paper_trail_uuid_test",
hostname: System.get_env("PG_HOST"),
hostname: System.get_env("PGHOST"),
show_sensitive_data_on_connection_error: true,
poolsize: 10

config :paper_trail, PaperTrail.UUIDWithCustomNameRepo,
adapter: Ecto.Adapters.Postgres,
username: System.get_env("POSTGRES_USER"),
password: System.get_env("POSTGRES_PASSWORD"),
username: System.get_env("PGUSER"),
password: System.get_env("PGPASSWORD"),
database: "paper_trail_uuid_with_custom_name_test",
hostname: System.get_env("PG_HOST"),
hostname: System.get_env("PGHOST"),
show_sensitive_data_on_connection_error: true,
poolsize: 10

config :logger, level: :warn
10 changes: 5 additions & 5 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ services:
db:
image: postgres:12.2-alpine
environment:
POSTGRES_PASSWORD: $POSTGRES_USER
POSTGRES_USER: $POSTGRES_PASSWORD
PGPASSWORD: $PGPASSWORD
PGUSER: $PGUSER
PGDATA: /var/lib/postgresql/data/pgdata
restart: always
networks:
Expand All @@ -19,10 +19,10 @@ services:
cache_from:
- $REGISTRY/$REPO_OWNER/$DOCKER_TAG
environment:
POSTGRES_USER: $POSTGRES_USER
POSTGRES_PASSWORD: $POSTGRES_PASSWORD
PGUSER: $PGUSER
PGPASSWORD: $PGPASSWORD
PGPORT: 5432
PG_HOST: db
PGHOST: db
MIX_ENV: $MIX_ENV
tty: true
depends_on:
Expand Down
4 changes: 2 additions & 2 deletions setup-database.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh
set -oe allexport
source .env
source ./.env

# Prepare Dialyzer if the project has Dialyxer set up
# if mix help dialyzer >/dev/null 2>&1
Expand All @@ -12,7 +12,7 @@ source .env
# fi

# Wait for Postgres to become available.
until psql -h $PG_HOST -U "$POSTGRES_USER" -c '\q' 2>/dev/null; do
until psql -h $PGHOST -U "$PGUSER" -c '\q' 2>/dev/null; do
>&2 echo "Postgres is unavailable - sleeping"
sleep 1
done
Expand Down

0 comments on commit 6cd5569

Please sign in to comment.