-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathRakefile
155 lines (123 loc) · 4.88 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# 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
trilogy_loaded = begin
require "activerecord-trilogy-adapter"
rescue LoadError
false
end
$LOAD_PATH << File.expand_path("lib", __dir__)
require "active_record_proxy_adapters"
require_relative "spec/test_helper"
if trilogy_loaded
ActiveSupport.on_load(:active_record) do
require "trilogy_adapter/connection"
ActiveRecord::Base.extend TrilogyAdapter::Connection
end
end
require "active_record_proxy_adapters/connection_handling"
ActiveSupport.on_load(:active_record) do
TestHelper.setup_active_record_config
$stdout.puts "Environment loaded: #{TestHelper.env_name}"
end
end
namespace :db do # rubocop:disable Metrics/BlockLength
desc "Drops all databases"
task drop: %i[drop:postgresql drop:mysql2 drop:trilogy]
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
desc "Drops the trilogy database"
task trilogy: :environment do
TestHelper.drop_trilogy_database
end
end
desc "Creates all databases"
task create: %i[create:postgresql create:mysql2 create:trilogy]
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
desc "Creates the trilogy database"
task trilogy: :environment do
TestHelper.create_trilogy_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 load:trilogy]
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
desc "Loads the schema into the trilogy database from schema_path. Default is db/mysql_structure.sql"
task :trilogy, [:schema_path] => :environment do |_task, args|
args.with_defaults(schema_path: "db/mysql_structure.sql")
TestHelper.load_trilogy_schema(args.schema_path)
end
end
desc "Dumps all schemas onto their respective files"
task dump: %i[dump:postgresql dump:mysql2 dump:trilogy]
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
desc "Dump the schema from the trilogy database onto schema_path. Default is db/mysql_structure.sql"
task :trilogy, [:schema_path] => :environment do |_task, args|
args.with_defaults(schema_path: "db/mysql_structure.sql")
TestHelper.dump_trilogy_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]
desc "Creates the trilogy database and loads the schema"
task trilogy: %i[create:trilogy schema:load:trilogy]
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