Skip to content

Instantly share code, notes, and snippets.

@aquajach
Created September 2, 2016 09:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aquajach/41f7fee405386fed200ca5bf6cfff783 to your computer and use it in GitHub Desktop.
Save aquajach/41f7fee405386fed200ca5bf6cfff783 to your computer and use it in GitHub Desktop.
#!/usr/bin/env rake
require "bundler/gem_tasks"
require 'active_record'
require 'rspec/core/rake_task'
require 'appraisal'
require 'pg'
RSpec::Core::RakeTask.new :spec
Bundler::GemHelper.install_tasks
task :default => [:spec]
namespace :db do
task :load_config do
ActiveRecord::Tasks::DatabaseTasks.root = File.dirname(__FILE__)
ActiveRecord::Base.configurations = YAML.load_file("#{File.dirname(__FILE__)}/spec/database.yml") || {}
end
desc "Creates the database from DATABASE_URL or config/database.yml for the current RAILS_ENV (use db:create:all to create all databases in the config). Without RAILS_ENV or when RAILS_ENV is development, it defaults to creating the development and test databases."
task create: [:load_config] do
ActiveRecord::Base.configurations.each do |adapter, config|
ActiveRecord::Tasks::DatabaseTasks.create_current(adapter)
if adapter == 'postgres'
conn = PG::Connection.open(dbname: config['database'])
conn.exec('CREATE EXTENSION IF NOT EXISTS pgcrypto')
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment