-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
99 lines (87 loc) · 2.19 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
$LOAD_PATH.unshift File.dirname(__FILE__)
require 'rake'
require 'core/irc'
include FireBat
def load_module(file, module_name)
load File.join('modules', file)
rescue => ex
puts "Error loading module #{module_name}: " + ex.to_s
end
def load_modules
Dir.foreach('modules') do |file|
if file =~ /^(.+)\.rb$/
module_name = Regexp.last_match[1]
load_module(file, module_name)
end
end
end
namespace :db do
namespace :install do
desc 'Install core tables'
task :core do
begin
Install.migrate :up
rescue => ex
puts ex.to_s
end
end
desc 'Install modules tables'
task :modules do
Dir.foreach('modules') do |file|
if file =~ /^(.+)\.rb$/
module_name = Regexp.last_match[1]
load_module(file, module_name)
klass = eval(module_name.camelize)
if klass.respond_to? :install
puts "Installing #{klass}"
begin
klass.install
rescue => ex
puts ex.to_s
end
end
end
end
end
end
desc 'Move data from mysql to postgresql.'
task :dump do
load_modules
establish_connection(
adapter: 'mysql2',
host: 'localhost',
username: 'root',
password: '',
database: 'rmudbot'
)
[
RmudItemCommand::RmudItem,
SowAdditemCommand::SowItem,
QuoteCommand::Quote,
BorCommand::Borquote,
FireBatCommand::User,
FireBatCommand::Role,
FireBatCommand::RolesUser
].each do |klass|
File.open(klass.name, 'wb') do |file|
Marshal.dump(klass.all.to_a, file)
end
end
end
desc 'Fix postgresql sequences.'
task :fix_pg_seq do
load_modules
{
RmudItemCommand::RmudItem => 'rmud_items_id_seq',
SowAdditemCommand::SowItem => 'sow_items_id_seq',
QuoteCommand::Quote => 'quotes_id_seq',
BorCommand::Borquote => 'borquotes_id_seq',
FireBatCommand::User => 'users_id_seq',
FireBatCommand::Role => 'roles_id_seq'
}.each_pair do |klass, seq|
ActiveRecord::Base.connection.execute(
"ALTER SEQUENCE #{seq} RESTART WITH #{klass.last.id + 1};"
)
end
end
end