OSDN Git Service

merge v04
[pettanr/pettanr.git] / db / migrate / 20120618023403_connect_story.rb
diff --git a/db/migrate/20120618023403_connect_story.rb b/db/migrate/20120618023403_connect_story.rb
new file mode 100644 (file)
index 0000000..1806125
--- /dev/null
@@ -0,0 +1,35 @@
+class ConnectStory < ActiveRecord::Migration
+  def up
+    pn = Panel.find :all
+    pn.each do |i|
+      c = i.comic_id
+      t = i.t
+      a = i.author_id
+      s = i.id
+      st = Story.find(:first, :conditions => ['comic_id = ? and panel_id = ? and t = ?', c, s, t])
+      st = Story.new(:comic_id => c, :panel_id => s, :t => t) unless st
+      st.author_id = a
+      st.save!
+    end
+    remove_column :comics, :editable
+    remove_column :panels, :comic_id
+    remove_column :panels, :t
+    add_column :panels, :publish, :integer, :null => false, :default => 0
+  end
+
+  def down
+    add_column :comics, :editable, :integer, :null => false, :default => 0
+    add_column :panels, :comic_id, :integer, :null => false, :default => 0
+    add_column :panels, :t, :integer, :null => false, :default => 0
+    remove_column :panels, :publish
+    st = Story.find :all
+    st.each do |i|
+      c = i.comic_id
+      t = i.t
+      pn = Panel.find(i.panel_id)
+      pn.t = t
+      pn.comic_id = c
+      pn.save!
+    end
+  end
+end