Class: Sufia::Models::AbstractMigrationGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
Rails::Generators::Migration
Defined in:
lib/generators/sufia/models/abstract_migration_generator.rb

Class Method Summary collapse

Class Method Details

.next_migration_number(path) ⇒ Object

Implement the required interface for Rails::Generators::Migration. taken from github.com/rails/rails/blob/master/activerecord/lib/generators/active_record.rb



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/generators/sufia/models/abstract_migration_generator.rb', line 10

def self.next_migration_number(path)
  if @prev_migration_nr
    @prev_migration_nr += 1
  else
    last_migration = Dir[File.join(path, '*.rb')].sort.last
    if last_migration
      @prev_migration_nr = last_migration.sub(File.join(path, '/'), '').to_i + 1
    else
      @prev_migration_nr = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
    end
  end
  @prev_migration_nr.to_s
end