diff --git a/.gitignore b/.gitignore index d5cc3093..a9907eab 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,6 @@ config/application.rb config/config.yml config/secrets.yml -config/database.yml config/piwik.yml /vendor/cache /vendor/cache-old diff --git a/.travis.yml b/.travis.yml index 0a13eca1..c7a8ebda 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,10 +22,8 @@ notifications: on_success: change on_failure: change 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;' - - RAILS_ENV=test bundle exec rake setup:bootstrap --trace + - RAILS_ENV=test bundle exec rake db:bootstrap --trace script: - "./travis_script.sh $TEST_SUITE" env: diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 26af8a1f..5f321f29 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -40,7 +40,7 @@ sed "s/13042/`id -u`/" docker-compose.override.yml.example > docker-compose.over 1. Set up the development environment: ```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: diff --git a/bin/osem-init.sh b/bin/osem-init.sh index 476469d0..b7d05dca 100755 --- a/bin/osem-init.sh +++ b/bin/osem-init.sh @@ -1,5 +1,5 @@ #!/bin/bash # Setup the app if it isn't already setup -bundle exec rake setup:bootstrap +bundle exec rake db:bootstrap # Start the app foreman start -p 3000 diff --git a/bootstrap.sh b/bootstrap.sh index 7c2c1cfe..3b331c23 100644 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -19,7 +19,7 @@ echo -e "\ninstalling your bundle...\n" su - vagrant -c "cd /vagrant/; bundle install --quiet" 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 "To start your development OSEM run: vagrant exec bundle exec rails server -b 0.0.0.0\n" diff --git a/config/database.yml.example b/config/database.yml similarity index 100% rename from config/database.yml.example rename to config/database.yml diff --git a/lib/tasks/db.rake b/lib/tasks/db.rake new file mode 100644 index 00000000..89299227 --- /dev/null +++ b/lib/tasks/db.rake @@ -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 diff --git a/lib/tasks/setup.rake b/lib/tasks/setup.rake deleted file mode 100644 index c5003cc5..00000000 --- a/lib/tasks/setup.rake +++ /dev/null @@ -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