Permalink
Browse files

properly generate slug migration

  • Loading branch information...
1 parent b0f2c3c commit b8dd6285052c02b61e686e2deb5c4ba294a96370 Brent Vatne committed May 28, 2012
@@ -14,8 +14,27 @@ def self.next_migration_number(path)
ActiveRecord::Generators::Base.next_migration_number(path)
end
- def generate_migration
- migration_template 'migration.rb', 'db/migrate/create_banyan_tables'
- migration_template 'slug_migration.rb', 'db/migrate/add_banyan_slugs'
+ # Public: Creates the migration files from the templates in /templates
+ #
+ # This, along with any other public instance method on this class, will be
+ # called when `rails g banyan` is executed. Order matters in migrations! Tables
+ # need to be created before slugs can be added to them; keep this in mind
+ # if you are going to add any.
+ def create_migrations
+ migrations = ['create_banyan_tables', 'add_banyan_slugs']
+
+ migrations.each do |migration_name|
+ create_migration_unless_it_exists(migration_name)
+ end
+ end
+
+ private
+
+ def create_migration_unless_it_exists(migration_name)
+ begin
+ migration_template "#{migration_name}.rb", "db/migrate/#{migration_name}"
+ rescue StandardError => e
+ puts e.message
+ end
end
end
@@ -5,6 +5,9 @@ def self.up
add_column :banyan_categories, :slug, :string
add_index :banyan_categories, :slug, :unique => true
+
+ Banyan::CategoryGroup.find_each(&:save)
+ Banyan::Category.find_each(&:save)
end
def self.down

0 comments on commit b8dd628

Please sign in to comment.