Created
September 7, 2020 18:56
-
-
Save ro31337/e76b6029d306aacb07ed8a5182abc140 to your computer and use it in GitHub Desktop.
Postgres for Rails setup that works, one shell script and database config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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