Permalink
Browse files

Add a generator for db migrations

  • Loading branch information...
1 parent ab1f43f commit acbfcc42766f581897629147bde2ffc7d7c0fb8c @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
* Fix Region / Country models failing to load in Ruby 1.9+ due to character encoding
@@ -0,0 +1,5 @@
+Usage:
+
+ script/generate has_addresses
+
+This will create migrations that will add the proper tables to store addresses.
@@ -0,0 +1,11 @@
+class HasAddressesGenerator < Rails::Generator::Base
+ def manifest
+ record do |m|
+ m.migration_template '001_create_countries.rb', 'db/migrate', :migration_file_name => 'create_countries'
+ m.sleep 1
+ m.migration_template '002_create_regions.rb', 'db/migrate', :migration_file_name => 'create_regions'
+ m.sleep 1
+ m.migration_template '003_create_addresses.rb', 'db/migrate', :migration_file_name => 'create_addresses'
+ end
+ end
+end
@@ -1,12 +1,12 @@
class MigrateHasAddressesToVersion3 < 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_addresses/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_addresses/templates", 0).migrations.each do |migration|
migration.migrate(:down)
end
end

0 comments on commit acbfcc4

Please sign in to comment.