forked from clio/polymorphic_integer_type
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
50 lines (43 loc) · 1.51 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
require "bundler/gem_tasks"
require "yaml"
require "active_record"
namespace :test do
task :all do
Dir.glob("./gemfiles/Gemfile*").each do |gemfile|
next if gemfile.end_with?(".lock")
puts "Running specs for #{Pathname.new(gemfile).basename}"
system("BUNDLE_GEMFILE=#{gemfile} bundle install > /dev/null && BUNDLE_GEMFILE=#{gemfile} bundle exec rspec")
puts ""
end
end
end
namespace :db do
database_config = YAML.load(File.open("./spec/support/database.yml"))
admin_database_config = database_config.merge(database: "mysql")
migration_path = File.expand_path("./spec/support/migrations")
desc "Create the database"
task :create do
ActiveRecord::Base.establish_connection(admin_database_config)
ActiveRecord::Base.connection.create_database(database_config.fetch(:database))
puts "Database created."
end
desc "Migrate the database"
task :migrate do
ActiveRecord::Base.establish_connection(database_config)
ActiveRecord::Migrator.migrate(migration_path)
Rake::Task["db:schema"].invoke
puts "Database migrated."
end
desc "Drop the database"
task :drop do
ActiveRecord::Base.establish_connection(admin_database_config)
ActiveRecord::Base.connection.drop_database(database_config.fetch(:database))
puts "Database deleted."
end
desc "Reset the database"
task reset: [:drop, :create, :migrate]
desc 'Create a db/schema.rb file that is portable against any DB supported by AR'
task :schema do
# Noop to make ActiveRecord happy
end
end