-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathRakefile
More file actions
54 lines (45 loc) · 1.54 KB
/
Rakefile
File metadata and controls
54 lines (45 loc) · 1.54 KB
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
51
52
53
54
# frozen_string_literal: true
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'))
migration_path = File.expand_path('./spec/support/migrations')
desc 'Create the database'
task :create do
# SQLite3 creates the database file automatically, just ensure directory exists
db_file = database_config.fetch(:database)
FileUtils.mkdir_p(File.dirname(db_file)) unless File.dirname(db_file) == '.'
puts 'Database ready (SQLite3).'
end
desc 'Migrate the database'
task :migrate do
ActiveRecord::Base.establish_connection(database_config)
ActiveRecord::MigrationContext.new(migration_path).migrate
Rake::Task['db:schema'].invoke
puts 'Database migrated.'
end
desc 'Drop the database'
task :drop do
# For SQLite3, just delete the file
db_file = database_config.fetch(:database)
File.delete(db_file) if File.exist?(db_file)
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