Class: Ridgepole::Delta
- Inherits:
-
Object
- Object
- Ridgepole::Delta
- Defined in:
- lib/ridgepole/delta.rb
Constant Summary collapse
- SCRIPT_NAME =
'<Schema>'.freeze
Instance Method Summary collapse
- #differ? ⇒ Boolean
-
#initialize(delta, options = {}) ⇒ Delta
constructor
A new instance of Delta.
- #migrate(options = {}) ⇒ Object
- #script ⇒ Object
Constructor Details
Instance Method Details
#differ? ⇒ Boolean
54 55 56 |
# File 'lib/ridgepole/delta.rb', line 54 def differ? !script.empty? || !delta_execute.empty? end |
#migrate(options = {}) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/ridgepole/delta.rb', line 11 def migrate( = {}) log_file = @options[:log_file] if log_file result = ActiveRecord::Migration.record_time do migrate0() end File.open(log_file, 'wb') { |f| f.puts JSON.pretty_generate(result) } result else migrate0() end end |
#script ⇒ Object
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 |
# File 'lib/ridgepole/delta.rb', line 26 def script buf = StringIO.new pre_buf_for_fk = StringIO.new post_buf_for_fk = StringIO.new (@delta[:add] || {}).each do |table_name, attrs| append_create_table(table_name, attrs, buf, post_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, pre_buf_for_fk, post_buf_for_fk) end (@delta[:delete] || {}).each do |table_name, attrs| append_drop_table(table_name, attrs, buf) end [ pre_buf_for_fk, buf, post_buf_for_fk ].map { |b| b.string.strip }.join("\n\n").strip end |