Created
September 2, 2016 09:26
-
-
Save aquajach/41f7fee405386fed200ca5bf6cfff783 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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