Sha256: 08b786caac3c9401adb4fa4c58804e2ca763ad64970ce4c9977d4e0fbabd2d8c

Contents?: true

Size: 1.03 KB

Versions: 3

Compression:

Stored size: 1.03 KB

Contents

require 'rails/generators'
require 'rails/generators/migration'

module OldSql
  class InstallMigrationsGenerator < Rails::Generators::Base
    include Rails::Generators::Migration
    source_root File.expand_path('../templates', __FILE__)
    argument :model_name, :type => :string, :default => 'user'

    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

    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}.rb" rescue p $!.message
      gsub_file "db/migrate/#{@migration_number}_add_old_sql_admin_to_#{model_name}.rb", /users/, "#{model_name}"
      #sleep 1 # ensure scripts have different timestamps
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
old_sql-1.43.0 lib/generators/old_sql/install_migrations_generator.rb
old_sql-1.42.0 lib/generators/old_sql/install_migrations_generator.rb
old_sql-1.39.0 lib/generators/old_sql/install_migrations_generator.rb