when i run command with $ rails new PROJECT with postgresql i realize struggle and tired that generate rails project files and setup database. if i got something wrong local environment such as rbenv, rvm on macOS or another OS. it's made me burnout.
docker-compose is perfect awesome developerment environment. when i generate rails project with docker-compose, i don't need any setup on local environment like ruby, rails version, database setup. docker-compose made easy setup rails project, database and another env.
$ git clone https://github.com/x1wins/rails-new-with-docker-compose.git
$ cd ./rails-new-with-docker-compose
$ docker-compose run --no-deps web rails new . --force --database=postgresql
$ vim config/database.yml
default: &default
adapter: postgresql
encoding: unicode
host: db
username: postgres
password: password
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
development:
<<: *default
database: myapp_development
test:
<<: *default
database: myapp_test
production:
<<: *default
database: myapp_production
username: myapp
password: <%= ENV['MYAPP_DATABASE_PASSWORD'] %>
docker-compose run --no-deps web bundle exec rake db:create
docker-compose run --no-deps web bundle exec rake db:migrate
docker-compose run --no-deps web bundle exec rake db:create RAILS_ENV=test
docker-compose run --no-deps web bundle exec rake db:migrate RAILS_ENV=test
or
docker-compose run --no-deps web bundle exec rake db:prepare
docker-compose up --build
docker-compose restart web
docker-compose run --no-deps web bundle exec rails console