OSDN Git Service

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