From 28eed457b2af554bec99174259ed67e5c52ecc80 Mon Sep 17 00:00:00 2001 From: Henne Vogelsang Date: Wed, 25 May 2016 14:41:16 +0200 Subject: [PATCH] Add a rake task to setup DATABASE_URL for ClearDB There currently is no other way to inherit environment variables from parent apps on heroku --- lib/tasks/cleardb.rake | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 lib/tasks/cleardb.rake diff --git a/lib/tasks/cleardb.rake b/lib/tasks/cleardb.rake new file mode 100644 index 00000000..4534e7ef --- /dev/null +++ b/lib/tasks/cleardb.rake @@ -0,0 +1,11 @@ +namespace :db do + desc 'setup DATABASE_URL from CLEARDB_DATABASE_URL in .env' + task cleardb_env: :environment 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 + end + end +end