forked from textacular/textacular
/
Rakefile
77 lines (61 loc) · 1.99 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
require "bundler/gem_tasks"
require 'active_record'
require 'pry'
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)
task :default => :spec
file 'spec/config.yml' do |t|
sh 'erb spec/config.yml.example > spec/config.yml'
end
desc 'Fire up an interactive terminal to play with'
task :console => :'db:connect' do
Pry.start
end
namespace :db do
task :connect => 'spec/config.yml' do |t|
ActiveRecord::Base.establish_connection \
YAML.load_file 'spec/config.yml'
end
task :disconnect do
ActiveRecord::Base.clear_all_connections!
end
desc 'Create the test database'
task :create do
sh 'createdb textacular'
end
desc 'Drop the test database'
task :drop => :disconnect do
sh 'dropdb textacular'
end
namespace :migrate do
desc 'Run the test database migrations'
task :up => :'db:connect' do
if ActiveRecord.version >= Gem::Version.new('6.0.0')
context = ActiveRecord::Migration.new.migration_context
migrations = context.migrations
schema_migration = context.schema_migration
elsif ActiveRecord.version >= Gem::Version.new('5.2')
migrations = ActiveRecord::Migration.new.migration_context.migrations
schema_migration = nil
else
migrations = ActiveRecord::Migrator.migrations('db/migrate')
schema_migration = nil
end
ActiveRecord::Migrator.new(:up, migrations, schema_migration).migrate
end
desc 'Reverse the test database migrations'
task :down => :'db:connect' do
migrations = if ActiveRecord.version.version >= '5.2'
ActiveRecord::Migration.new.migration_context.migrations
else
ActiveRecord::Migrator.migrations('db/migrate')
end
ActiveRecord::Migrator.new(:down, migrations, nil).migrate
end
end
task :migrate => :'migrate:up'
desc 'Create and configure the test database'
task :setup => [ :create, :migrate ]
desc 'Drop the test tables and database'
task :teardown => [ :'migrate:down', :drop ]
end