From a3dd8e6c958eddc894deb3d811652fdf75362eed Mon Sep 17 00:00:00 2001 From: Henne Vogelsang Date: Wed, 25 May 2016 15:12:30 +0200 Subject: [PATCH] Use config/database.yml for ClearDB config If we use .env heroku neither sees DATABASE_URL nor config/database.yml and assumes we use postgre. There also is no need to load the rails env in the task. --- config/database.yml.heroku | 2 ++ lib/tasks/cleardb.rake | 9 +++------ 2 files changed, 5 insertions(+), 6 deletions(-) create mode 100644 config/database.yml.heroku diff --git a/config/database.yml.heroku b/config/database.yml.heroku new file mode 100644 index 00000000..f0886077 --- /dev/null +++ b/config/database.yml.heroku @@ -0,0 +1,2 @@ +production: + url: <%= ENV["CLEARDB_DATABASE_URL"].sub(/^mysql/, "mysql2") %> diff --git a/lib/tasks/cleardb.rake b/lib/tasks/cleardb.rake index 4534e7ef..ca2a32ae 100644 --- a/lib/tasks/cleardb.rake +++ b/lib/tasks/cleardb.rake @@ -1,11 +1,8 @@ namespace :db do - desc 'setup DATABASE_URL from CLEARDB_DATABASE_URL in .env' - task cleardb_env: :environment do + desc 'setup DATABASE_URL from CLEARDB_DATABASE_URL in config/database.yml' + task 'cleardb_env' do unless ENV['CLEARDB_DATABASE_URL'].nil? - cleardb_url = ENV['CLEARDB_DATABASE_URL'].gsub(/^mysql:\/\//, 'mysql2://') - dot_env = File.open(Rails.root.join(".env"), 'w') - dot_env.puts "DATABASE_URL=\"#{cleardb_url}\"" - dot_env.close + FileUtils.copy_file('config/database.yml.heroku', 'config/database.yml') end end end