Skip to content

Instantly share code, notes, and snippets.

@ro31337
Created September 7, 2020 18:56
Show Gist options
  • Save ro31337/e76b6029d306aacb07ed8a5182abc140 to your computer and use it in GitHub Desktop.
Save ro31337/e76b6029d306aacb07ed8a5182abc140 to your computer and use it in GitHub Desktop.
Postgres for Rails setup that works, one shell script and database config
default: &default
timeout: 5000
adapter: postgresql
encoding: unicode
database: sample_postgres_development
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
username: xxx
password: xxx
host: localhost
port: 5432
development:
<<: *default
database: xxx
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: xxx_test
production:
<<: *default
database: xxx
#!/bin/bash
CID=$(
docker run -d -v xxx:/var/lib/postgresql/data \
-p 127.0.0.1:5432:5432 -e POSTGRES_USER=xxx \
-e POSTGRES_PASSWORD=xxx postgres
)
IPADDR=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' $CID)
cat << EOF
=== DOCKER INFO: ===
IP/PORT: $IPADDR:5432
=== COMMANDS HELP: ===
psql -U xxx
Run PostgreSQL CLI
\c xxx
Connect to the database
\dt+
List tables in the database
exit
Exit from PostgreSQL CLI
EOF
docker exec -ti $CID bash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment