From a3dd8e6c958eddc894deb3d811652fdf75362eed Mon Sep 17 00:00:00 2001 From: Henne Vogelsang Date: Wed, 25 May 2016 15:12:30 +0200 Subject: [PATCH 1/2] 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 From c2a706d0a10b2d7f10bf340d349eb00cd3cf357b Mon Sep 17 00:00:00 2001 From: Henne Vogelsang Date: Wed, 25 May 2016 16:58:21 +0200 Subject: [PATCH 2/2] Apparently something at heroku tries to .tr this... --- app.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app.json b/app.json index a65ae0b1..37164c50 100644 --- a/app.json +++ b/app.json @@ -5,7 +5,9 @@ "CLOUDINARY_URL": { "required": true }, - "DATABASE_URL": "WILL_NOT_BE_USED", + "DATABASE_URL": { + "required": true + }, "DEPLOY_TASKS": "db:cleardb_env", "LANG": { "required": true