-
Notifications
You must be signed in to change notification settings - Fork 1
/
Rakefile
44 lines (36 loc) · 1.27 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
require 'bundler/gem_tasks'
namespace :test do
namespace :db do
desc "Create test database"
task :create do
require_relative './spec/config/test_database.rb'
db = TestDatabase.new
case db.type
when :postgres
require 'pg'
db.connect 'postgres'
ActiveRecord::Base.connection.execute "CREATE DATABASE #{db.name} ENCODING='UTF-8'"
when :mysql
require 'mysql2'
client_config = db.configuration
.merge(database: nil,
username: 'root',
password: ENV['DB_ROOT_PASSWORD'],
flags: Mysql2::Client::MULTI_STATEMENTS)
client = Mysql2::Client.new(client_config)
client.query <<-SQL
CREATE DATABASE #{db.name};
GRANT ALL ON #{db.name}.* TO '#{db.configuration['username']}'@'#{db.configuration['host']}';
FLUSH PRIVILEGES;
SQL
else
raise "Unknown database type: #{db.type}"
end
puts "Test database \"#{db.name}\" created."
end
end
end
desc "Benchmark all available solutions to import CSV in Postgres database"
task :benchmark do
require_relative 'benchmark/benchmark'
end