-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathRakefile
116 lines (91 loc) · 3.61 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# frozen_string_literal: true
require "bundler/gem_tasks"
require "rspec/core/rake_task"
RSpec::Core::RakeTask.new(:spec)
require "rubocop/rake_task"
RuboCop::RakeTask.new
task default: %i[spec rubocop]
desc "Prepares the database environment for use"
task :environment do
$LOAD_PATH << File.expand_path("lib", __dir__)
require "active_record_proxy_adapters"
require "active_record_proxy_adapters/connection_handling"
ActiveRecord::Base.extend ActiveRecordProxyAdapters::ConnectionHandling
require_relative "spec/test_helper"
TestHelper.setup_active_record_config
$stdout.puts "Environment loaded: #{TestHelper.env_name}"
end
namespace :db do # rubocop:disable Metrics/BlockLength
desc "Drops all databases"
task drop: %i[drop:postgresql drop:mysql2]
namespace :drop do
desc "Drops the postgresql database"
task postgresql: :environment do
TestHelper.drop_postgresql_database
end
desc "Drops the mysql database"
task mysql2: :environment do
TestHelper.drop_mysql2_database
end
end
desc "Creates all databases"
task create: %i[create:postgresql create:mysql2]
namespace :create do
desc "Creates the postgresql database"
task postgresql: :environment do
TestHelper.create_postgresql_database
end
desc "Creates the mysql database"
task mysql2: :environment do
TestHelper.create_mysql2_database
end
end
namespace :schema do # rubocop:disable Metrics/BlockLength
desc "Loads all schemas onto their respective databases"
task load: %i[load:postgresql load:mysql2]
namespace :load do
desc "Loads the schema into the postgresql database from schema_path. Default is db/postgresql_structure.sql"
task :postgresql, [:schema_path] => :environment do |_task, args|
args.with_defaults(schema_path: "db/postgresql_structure.sql")
TestHelper.load_postgresql_schema(args.schema_path)
end
desc "Loads the schema into the mysql database from schema_path. Default is db/mysql_structure.sql"
task :mysql2, [:schema_path] => :environment do |_task, args|
args.with_defaults(schema_path: "db/mysql_structure.sql")
TestHelper.load_mysql2_schema(args.schema_path)
end
end
desc "Dumps all schemas onto their respective files"
task dump: %i[dump:postgresql dump:mysql2]
namespace :dump do
desc "Dump the schema from the postgresql database onto schema_path. Default is db/postgresql_structure.sql"
task :postgresql, [:schema_path] => :environment do |_task, args|
args.with_defaults(schema_path: "db/postgresql_structure.sql")
TestHelper.dump_postgresql_schema(args.schema_path)
end
desc "Dump the schema from the mysql database onto schema_path. Default is db/mysql_structure.sql"
task :mysql2, [:schema_path] => :environment do |_task, args|
args.with_defaults(schema_path: "db/mysql_structure.sql")
TestHelper.dump_mysql2_schema(args.schema_path)
end
end
end
desc "Creates a all databases and loads their schemas"
task setup: %i[create schema:load]
namespace :setup do
desc "Creates the postgresql database and loads the schema"
task postgresql: %i[create:postgresql schema:load:postgresql]
desc "Creates the mysql2 database and loads the schema"
task mysql2: %i[create:mysql2 schema:load:mysql2]
end
end
namespace :coverage do
desc "Collates all result sets generated by the different test runners"
task :report do
require "simplecov"
require_relative "spec/simple_cov_groups"
SimpleCov.collate Dir["coverage/**/.resultset.json"] do
SIMPLE_COV_GROUPS.call
end
end
end