Class: Ridgepole::Delta
- Inherits:
-
Object
- Object
- Ridgepole::Delta
- Defined in:
- lib/ridgepole/delta.rb
Constant Summary collapse
- SCRIPT_NAME =
'<Schema>'
Instance Method Summary collapse
- #differ? ⇒ Boolean
-
#initialize(delta, options = {}) ⇒ Delta
constructor
A new instance of Delta.
- #migrate(options = {}) ⇒ Object
- #script ⇒ Object
Constructor Details
#initialize(delta, options = {}) ⇒ Delta
4 5 6 7 8 |
# File 'lib/ridgepole/delta.rb', line 4 def initialize(delta, = {}) @delta = delta = @logger = Ridgepole::Logger.instance end |
Instance Method Details
#differ? ⇒ Boolean
46 47 48 |
# File 'lib/ridgepole/delta.rb', line 46 def differ? not script.empty? or not delta_execute.empty? end |
#migrate(options = {}) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/ridgepole/delta.rb', line 10 def migrate( = {}) if log_file = [:log_file] result = ActiveRecord::Migration.record_time do migrate0() end open(log_file, 'wb') {|f| f.puts JSON.pretty_generate(result) } result else migrate0() end end |
#script ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/ridgepole/delta.rb', line 23 def script buf = StringIO.new buf_for_fk = StringIO.new (@delta[:add] || {}).each do |table_name, attrs| append_create_table(table_name, attrs, buf, buf_for_fk) end (@delta[:rename] || {}).each do |table_name, attrs| append_rename_table(table_name, attrs, buf) end (@delta[:change] || {}).each do |table_name, attrs| append_change(table_name, attrs, buf, buf_for_fk) end (@delta[:delete] || {}).each do |table_name, attrs| append_drop_table(table_name, attrs, buf) end (buf.string.strip + "\n\n" + buf_for_fk.string.strip).strip end |