Put database.yml into the code base

It works by default, we have a mechanism to configure it (dotenv.example)
and we want to be a 12factor app, right? Let's do this...
This commit is contained in:
Henne Vogelsang 2018-09-18 22:58:34 +02:00 committed by James Mason
parent a0b79c7789
commit f8b7233404
8 changed files with 22 additions and 55 deletions

1
.gitignore vendored
View file

@ -2,7 +2,6 @@
config/application.rb config/application.rb
config/config.yml config/config.yml
config/secrets.yml config/secrets.yml
config/database.yml
config/piwik.yml config/piwik.yml
/vendor/cache /vendor/cache
/vendor/cache-old /vendor/cache-old

View file

@ -22,10 +22,8 @@ notifications:
on_success: change on_success: change
on_failure: change on_failure: change
before_script: before_script:
- cp config/database.yml.example config/database.yml
- cp config/secrets.yml.example config/secrets.yml
- mysql -u root -e 'create database osem_test;' - mysql -u root -e 'create database osem_test;'
- RAILS_ENV=test bundle exec rake setup:bootstrap --trace - RAILS_ENV=test bundle exec rake db:bootstrap --trace
script: script:
- "./travis_script.sh $TEST_SUITE" - "./travis_script.sh $TEST_SUITE"
env: env:

View file

@ -40,7 +40,7 @@ sed "s/13042/`id -u`/" docker-compose.override.yml.example > docker-compose.over
1. Set up the development environment: 1. Set up the development environment:
```bash ```bash
docker-compose run --rm osem bundle exec rake setup:bootstrap docker-compose run --rm osem bundle exec rake db:bootstrap
``` ```
1. Start the development environment: 1. Start the development environment:

View file

@ -1,5 +1,5 @@
#!/bin/bash #!/bin/bash
# Setup the app if it isn't already setup # Setup the app if it isn't already setup
bundle exec rake setup:bootstrap bundle exec rake db:bootstrap
# Start the app # Start the app
foreman start -p 3000 foreman start -p 3000

View file

@ -19,7 +19,7 @@ echo -e "\ninstalling your bundle...\n"
su - vagrant -c "cd /vagrant/; bundle install --quiet" su - vagrant -c "cd /vagrant/; bundle install --quiet"
echo -e "\nConfiguring the app...\n" echo -e "\nConfiguring the app...\n"
su - vagrant -c "cd /vagrant/; bundle exec rake setup:bootstrap" su - vagrant -c "cd /vagrant/; bundle exec rake db:bootstrap"
echo -e "\nProvisioning of your OSEM rails app done!" echo -e "\nProvisioning of your OSEM rails app done!"
echo -e "To start your development OSEM run: vagrant exec bundle exec rails server -b 0.0.0.0\n" echo -e "To start your development OSEM run: vagrant exec bundle exec rails server -b 0.0.0.0\n"

18
lib/tasks/db.rake Normal file
View file

@ -0,0 +1,18 @@
# frozen_string_literal: true
namespace :db do
desc 'Bootstrap the database for the current RAILS_ENV (create, setup & seed if the database does not exist)'
task bootstrap: :environment do
puts 'Bootstrapping the database...'
begin
# Only do this if the database does not exist...
Rake::Task['db:version'].invoke
# rubocop:disable Style/RescueStandardError
rescue
# rubocop:enable Style/RescueStandardError
Rake::Task['db:create'].invoke
Rake::Task['db:setup'].invoke
Rake::Task['db:seed'].invoke
end
end
end

View file

@ -1,48 +0,0 @@
# frozen_string_literal: true
require 'fileutils'
namespace :setup do
task :configure do
puts 'Setting up the database configuration...'
copy_example_file('config/database.yml')
copy_example_file(".env.#{Rails.env}", 'dotenv.example')
end
desc 'Bootstrap the application'
task bootstrap: [:configure, :environment] do
puts 'Creating the database...'
begin
# Only do this if the database does not exist...
Rake::Task['db:version'].invoke
# rubocop:disable Style/RescueStandardError
rescue
# rubocop:enable Style/RescueStandardError
Rake::Task['db:create'].invoke
Rake::Task['db:setup'].invoke
Rake::Task['db:seed'].invoke
end
if Rails.env.test? || Rails.env.production?
puts 'Prepare assets'
Rake::Task['assets:clobber'].invoke
Rake::Task['assets:precompile'].invoke
end
if Rails.env.development?
puts 'Removing assets'
Rake::Task['assets:clobber'].invoke
end
end
end
def copy_example_file(example_file, source_file = nil)
if File.exist?(example_file) && !ENV['FORCE_EXAMPLE_FILES']
example_file = File.join(File.expand_path(File.dirname(__FILE__) + '/../..'), example_file)
puts "WARNING: You already have the config file #{example_file}, skipping..."
else
source_file ||= "#{example_file}.example"
puts "Creating #{example_file} from #{source_file}"
FileUtils.copy_file(source_file, example_file)
end
end