Permalink
Browse files

Add a generator for db migrations

  • Loading branch information...
1 parent 7a3e598 commit 4d5300b11cfb6bd5e78e33886564791a45c8e8cd @obrie obrie committed Mar 1, 2010
View
@@ -1,5 +1,6 @@
== master
+* Add a generator for db migrations
* Release gems via rake-gemcutter instead of rubyforge
== 0.3.0 / 2009-04-30
View
@@ -32,6 +32,17 @@ how they are persisted.
Note that this is a reference implementation and, most likely, should be
modified for your own usage.
+=== Installation
+
++has_ratings+ requires additional database tables to work. You can generate
+a migration for these tables like so:
+
+ script/generate has_ratings
+
+Then simply migrate your database:
+
+ rake db:migrate
+
=== Example
user = User.find(1)
View
@@ -11,7 +11,7 @@ spec = Gem::Specification.new do |s|
s.summary = 'Demonstrates a reference implementation for handling ratings in ActiveRecord'
s.description = s.summary
- s.files = FileList['{app,assets,db,lib,test}/**/*'] + %w(CHANGELOG.rdoc init.rb LICENSE Rakefile README.rdoc) - FileList['test/app_root/{log,log/*,script,script/*}']
+ s.files = FileList['{app,assets,generators,lib,test}/**/*'] + %w(CHANGELOG.rdoc init.rb LICENSE Rakefile README.rdoc) - FileList['test/app_root/{log,log/*,script,script/*}']
s.require_path = 'lib'
s.has_rdoc = true
s.test_files = Dir['test/**/*_test.rb']
@@ -0,0 +1,5 @@
+Usage:
+
+ script/generate has_ratings
+
+This will create migrations that will add the proper tables to store ratings.
@@ -0,0 +1,9 @@
+class HasRatingsGenerator < Rails::Generator::Base
+ def manifest
+ record do |m|
+ m.migration_template '001_create_rating_values.rb', 'db/migrate', :migration_file_name => 'create_rating_values'
+ m.sleep 1
+ m.migration_template '002_create_ratings.rb', 'db/migrate', :migration_file_name => 'create_ratings'
+ end
+ end
+end
@@ -1,12 +1,12 @@
class MigrateHasRatingsToVersion2 < ActiveRecord::Migration
def self.up
- ActiveRecord::Migrator.new(:up, "#{Rails.root}/../../db/migrate", 0).migrations.each do |migration|
+ ActiveRecord::Migrator.new(:up, "#{Rails.root}/../../generators/has_ratings/templates", 0).migrations.each do |migration|
migration.migrate(:up)
end
end
def self.down
- ActiveRecord::Migrator.new(:up, "#{Rails.root}/../../db/migrate", 0).migrations.each do |migration|
+ ActiveRecord::Migrator.new(:down, "#{Rails.root}/../../generators/has_ratings/templates", 0).migrations.each do |migration|
migration.migrate(:down)
end
end

0 comments on commit 4d5300b

Please sign in to comment.