aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorPhilip Arndt <parndt@gmail.com>2011-03-02 15:32:20 +1300
committerPhilip Arndt <parndt@gmail.com>2011-03-02 15:32:20 +1300
commit559ef9b3cba34dbe438c72cf7f85850f08dec92a (patch)
treeda3e1aecb25e0ecf0875c3add4a9367f138b5963 /lib
parent2cfc0c142cfecee70c82b68935f4232040b83376 (diff)
downloadrefinerycms-blog-559ef9b3cba34dbe438c72cf7f85850f08dec92a.tar.gz
refinerycms-blog-559ef9b3cba34dbe438c72cf7f85850f08dec92a.tar.bz2
refinerycms-blog-559ef9b3cba34dbe438c72cf7f85850f08dec92a.zip
Added new migration to add the user_id column to blog_posts. The madness must end, we must move to EngineInstaller in the next version.
Diffstat (limited to 'lib')
-rw-r--r--lib/generators/refinerycms_blog/templates/db/migrate/migration_number_add_user_id_to_blog_posts.rb11
-rw-r--r--lib/generators/refinerycms_blog_generator.rb21
2 files changed, 25 insertions, 7 deletions
diff --git a/lib/generators/refinerycms_blog/templates/db/migrate/migration_number_add_user_id_to_blog_posts.rb b/lib/generators/refinerycms_blog/templates/db/migrate/migration_number_add_user_id_to_blog_posts.rb
new file mode 100644
index 0000000..cd62524
--- /dev/null
+++ b/lib/generators/refinerycms_blog/templates/db/migrate/migration_number_add_user_id_to_blog_posts.rb
@@ -0,0 +1,11 @@
+class AddUserIdToBlogPosts < ActiveRecord::Migration
+
+ def self.up
+ add_column :blog_posts, :user_id, :integer
+ end
+
+ def self.down
+ remove_column :blog_posts, :user_id
+ end
+
+end \ No newline at end of file
diff --git a/lib/generators/refinerycms_blog_generator.rb b/lib/generators/refinerycms_blog_generator.rb
index a801353..86c96ec 100644
--- a/lib/generators/refinerycms_blog_generator.rb
+++ b/lib/generators/refinerycms_blog_generator.rb
@@ -41,14 +41,21 @@ class RefinerycmsBlogGenerator < Rails::Generators::NamedBase
Rails::Generators::GeneratedAttribute.new('blog_post_id', 'integer')
], :id => false
}]
- next_migration_number = ActiveRecord::Generators::Base.next_migration_number(File.dirname(__FILE__))
- template('db/migrate/migration_number_create_singular_name.rb',
- Rails.root.join("db/migrate/#{next_migration_number}_create_#{singular_name}.rb"))
+ unless Pathname.glob(Rails.root.join('db', 'migrate', "*_create_#{singular_name}.rb")).any?
+ next_migration_number = ActiveRecord::Generators::Base.next_migration_number(File.dirname(__FILE__))
+ template('db/migrate/migration_number_create_singular_name.rb',
+ Rails.root.join("db/migrate/#{next_migration_number}_create_#{singular_name}.rb"))
+ end
+ unless Pathname.glob(Rails.root.join('db', 'migrate', "*_add_user_id_to_blog_posts.rb")).any?
+ next_migration_number = ActiveRecord::Generators::Base.next_migration_number(File.dirname(__FILE__))
+ template('db/migrate/migration_number_add_user_id_to_blog_posts.rb',
+ Rails.root.join('db', 'migrate', "#{next_migration_number}_add_user_id_to_blog_posts.rb"))
+ end
- puts "------------------------"
- puts "Now run:"
- puts "rake db:migrate"
- puts "------------------------"
+ puts "------------------------"
+ puts "Now run:"
+ puts "rake db:migrate"
+ puts "------------------------"
end
end