forked from ManageIQ/pg-logical_replication
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Rakefile
52 lines (43 loc) · 1.25 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
require "bundler/gem_tasks"
require "rspec/core/rake_task"
require_relative "spec/support/database_helper"
require_relative "spec/support/connection_helper"
def create_database(dbname)
c = ConnectionHelper.connection_for("postgres")
c.async_exec("CREATE DATABASE #{dbname}")
rescue PG::DuplicateDatabase => err
raise unless err.message =~ /already exists/
end
def create_tables(dbname)
c = ConnectionHelper.connection_for(dbname)
DatabaseHelper.tables.each do |t|
c.async_exec(<<-SQL)
CREATE TABLE IF NOT EXISTS #{t} (
id SERIAL PRIMARY KEY,
data VARCHAR(50)
)
SQL
end
end
def drop_database(dbname)
c = ConnectionHelper.connection_for("postgres")
c.async_exec("DROP DATABASE #{dbname}")
rescue PG::InvalidCatalogName => err
raise unless err.message =~ /does not exist/
end
namespace :spec do
desc "Setup the test databases"
task :setup => :teardown do
create_database("logical_test")
create_database("logical_test_target")
create_tables("logical_test")
create_tables("logical_test_target")
end
desc "Teardown the test databases"
task :teardown do
drop_database("logical_test")
drop_database("logical_test_target")
end
end
RSpec::Core::RakeTask.new(:spec)
task :default => :spec