Class: ActiveRecord::PtOscMigration
- Inherits:
-
Migration
- Object
- Migration
- ActiveRecord::PtOscMigration
show all
- Defined in:
- lib/active_record/pt_osc_migration.rb
Constant Summary
collapse
- PERCONA_FLAGS =
{
'defaults-file' => {
mutator: :make_path_absolute,
},
'recursion-method' => {
version: '>= 2.1',
},
'execute' => {
default: false,
},
'check-alter' => {
boolean: true,
default: true,
mutator: :execute_only,
version: '>= 2.1',
},
'user' => {
mutator: :get_from_config,
arguments: {
key_name: 'username',
},
default: nil,
},
'password' => {
mutator: :get_from_config,
default: nil,
},
}.freeze
Class Method Summary
collapse
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *arguments, &block) ⇒ Object
91
92
93
94
|
# File 'lib/active_record/pt_osc_migration.rb', line 91
def method_missing(method, *arguments, &block) super
end
|
Class Method Details
.percona_flags ⇒ Object
37
38
39
|
# File 'lib/active_record/pt_osc_migration.rb', line 37
def self.percona_flags
PERCONA_FLAGS
end
|
Instance Method Details
#migrate(direction) ⇒ Object
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
|
# File 'lib/active_record/pt_osc_migration.rb', line 41
def migrate(direction)
return unless respond_to?(direction)
run_mode = percona_config[:run_mode] || 'print'
raise ArgumentError.new('Invalid run_mode specified in database config') unless run_mode.in? %w(print execute)
case direction
when :up then announce 'migrating'
when :down then announce 'reverting'
end
time = nil
ActiveRecord::Base.connection_pool.with_connection do |conn|
@connection = conn
if respond_to?(:change)
if direction == :down
recorder = CommandRecorder.new(@connection)
suppress_messages do
@connection = recorder
change
end
@connection = conn
time = Benchmark.measure {
self.revert {
recorder.inverse.each do |cmd, args|
send(cmd, *args)
end
}
}
else
time = Benchmark.measure { change }
end
else
time = Benchmark.measure { send(direction) }
end
case run_mode
when 'execute' then time += Benchmark.measure { execute_pt_osc }
when 'print' then print_pt_osc
end
@connection = nil
end
case direction
when :up then announce 'migrated (%.4fs)' % time.real; write
when :down then announce 'reverted (%.4fs)' % time.real; write
end
end
|