Permalink
Browse files

Populate newsposts in a migration

Instead of using a script, it's much cleaner to handle this as a
migration.
  • Loading branch information...
1 parent 0dbebb4 commit 69d04c47e05e0257579297e139f4e9bbd15227d3 @mistydemeo committed Aug 12, 2012
Showing with 20 additions and 16 deletions.
  1. +0 −16 bin/create_newsposts
  2. +20 −0 db/migrate/20120812173636_create_newsposts.rb
View
@@ -1,16 +0,0 @@
-#!/usr/bin/env ruby
-# This tool just migrates the newsposts into a database
-$: << File.join(__FILE__, "../..")
-$: << File.join(__FILE__, "../lib")
-
-require 'app'
-require "preeventualist/newsposts"
-
-perry = Poster.new
-perry.name = "perry"
-perry.save
-
-Newsposts.each do |contents|
- post = perry.posts.new contents
- post.save
-end
@@ -0,0 +1,20 @@
+# This populates the database with newsposts
+# These are canned because every newspost has already been written!
+
+require "preeventualist/newsposts"
+
+class CreateNewsposts < ActiveRecord::Migration
+ def up
+ perry = Poster.new name: "perry"
+ perry.save
+ Newsposts.each do |contents|
+ post = perry.posts.new contents
+ post.save
+ end
+ end
+
+ def down
+ Post.all.each(&:delete)
+ Poster.all.each(&:delete)
+ end
+end

0 comments on commit 69d04c4

Please sign in to comment.