OSDN Git Service

rails upgrade to 4
[pettanr/pettanr.git] / db / migrate / 20120618023403_connect_story.rb
1 class ConnectStory < ActiveRecord::Migration
2   def up
3     pn = Panel.find_each do |i|
4       c = i.comic_id
5       t = i.t
6       a = i.author_id
7       s = i.id
8       st = Story.where(['comic_id = ? and panel_id = ? and t = ?', c, s, t]).first
9       st = Story.new(:comic_id => c, :panel_id => s, :t => t) unless st
10       st.author_id = a
11       st.save!
12     end
13     remove_column :comics, :editable
14     remove_column :panels, :comic_id
15     remove_column :panels, :t
16     add_column :panels, :publish, :integer, :null => false, :default => 0
17   end
18
19   def down
20     add_column :comics, :editable, :integer, :null => false, :default => 0
21     add_column :panels, :comic_id, :integer, :null => false, :default => 0
22     add_column :panels, :t, :integer, :null => false, :default => 0
23     remove_column :panels, :publish
24     st = Story.find_each do |i|
25       c = i.comic_id
26       t = i.t
27       pn = Panel.find(i.panel_id)
28       pn.t = t
29       pn.comic_id = c
30       pn.save!
31     end
32   end
33 end