OSDN Git Service

add comic story
[pettanr/pettanr.git] / db / migrate / 20140520102407_rm_comic_id_on_story.rb
diff --git a/db/migrate/20140520102407_rm_comic_id_on_story.rb b/db/migrate/20140520102407_rm_comic_id_on_story.rb
new file mode 100644 (file)
index 0000000..fc52a7b
--- /dev/null
@@ -0,0 +1,17 @@
+class RmComicIdOnStory < ActiveRecord::Migration
+  def up
+    add_column :stories, :author_id, :integer, :null => false, :default => 0
+    Story.all.each do |s|
+      c = Comic.find(s.comic_id)
+      ComicStory.create! :comic_id => s.comic_id, :story_id => s.id,
+        :author_id => c.author_id, :t => s.t
+      s.author_id = c.author_id
+      s.save!
+    end
+    remove_column :stories, :comic_id
+    remove_column :stories, :t
+  end
+
+  def down
+  end
+end