Class: ChangeContentForHstore
- Inherits:
-
ActiveRecord::Migration
- Object
- ActiveRecord::Migration
- ChangeContentForHstore
- Defined in:
- lib/ecrire/db/migrate/20160501848734_change_content_for_hstore.rb
Defined Under Namespace
Classes: Post
Instance Method Summary collapse
Instance Method Details
#down ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/ecrire/db/migrate/20160501848734_change_content_for_hstore.rb', line 23 def down change_table :posts do |t| t.text :compiled_content t.text :new_content end Post.each do |p| p.content = p.new_content['raw'] p.compiled_content = p.new_content['html'] p.save end change_table :posts do |t| t.remove :content t.rename :new_content, :content end end |
#up ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/ecrire/db/migrate/20160501848734_change_content_for_hstore.rb', line 5 def up change_table :posts do |t| t.column :new_content, :hstore, default: {raw: '', html: ''} end Post.all.each do |p| p.new_content['raw'] = p.content p.new_content['html'] = p.compiled_content p.save end change_table :posts do |t| t.remove :compiled_content t.remove :content t.rename :new_content, :content end end |