Class: OldSql::InstallMigrationsGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
Rails::Generators::Migration
Defined in:
lib/generators/old_sql/install_migrations_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.next_migration_number(dirname) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/generators/old_sql/install_migrations_generator.rb', line 10

def self.next_migration_number(dirname)
  if ActiveRecord::Base.timestamped_migrations
    @migration_number = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
    @migration_number += 1
    @migration_number.to_s
  else
    @migration_number = "%.3d" % (current_migration_number(dirname) + 1)
  end
end

Instance Method Details

#create_migration_fileObject



20
21
22
23
24
25
26
# File 'lib/generators/old_sql/install_migrations_generator.rb', line 20

def create_migration_file
  sleep 1 # ensure scripts have different timestamps
  migration_template 'add_old_sql_admin_to_users_migration.rb', "db/migrate/add_old_sql_admin_to_#{model_name.pluralize}.rb" rescue p $!.message
  gsub_file "db/migrate/#{@migration_number}_add_old_sql_admin_to_#{model_name.pluralize}.rb", /devise_model/, "#{model_name.pluralize}"
  gsub_file "db/migrate/#{@migration_number}_add_old_sql_admin_to_#{model_name.pluralize}.rb", /DeviseModel/, "#{model_name.pluralize.capitalize}"
  #sleep 1 # ensure scripts have different timestamps
end