forked from ckruse/cforum
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRakefile
71 lines (57 loc) · 1.8 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
#!/usr/bin/env rake
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require File.expand_path('../config/application', __FILE__)
require 'rake'
require 'rake/testtask'
class Rake::Task
def overwrite(&block)
@full_comment = nil
@actions.clear
prerequisites.clear
enhance(&block)
end
def abandon
@full_comment = nil
prerequisites.clear
@actions.clear
end
end
Cforum::Application.load_tasks
namespace :db do |x|
namespace :structure do |schema|
schema[:dump].abandon
task :dump => :environment do
config = ActiveRecord::Base.configurations[Rails.env]
args = "-sxO"
args << ' -h ' + config['host'] unless config['host'].blank?
args << ' -U ' + config['username'] unless config['username'].blank?
system "pg_dump #{args} #{config['database']} > db/structure.sql"
File.open("#{Rails.root}/db/structure.sql", "a") do |f|
f << ActiveRecord::Base.connection.dump_schema_information
end
end
end
end
Rake::Task['db:create'].enhance do
ActiveRecord::Base.configurations.each do |name, config|
begin
ActiveRecord::Base.establish_connection config
schema = config['schema_search_path'].split(",").first
res = ActiveRecord::Base.connection.execute "SELECT schema_name FROM information_schema.schemata WHERE schema_name = '" + schema + "'"
ActiveRecord::Base.connection.execute "CREATE SCHEMA " + schema if res.ntuples == 0
rescue
end
end
#Rake::Task['db:after_create'].invoke
end
namespace :test do
Rake::TestTask.new :plugins do |t|
t.libs << 'test'
t.pattern = 'test/plugins/**/*_test.rb'
end
end
Rake::Task['test:run'].enhance do
Rake::Task['test:plugins'].invoke
end
# eof