Sha256: 7c2b18a8e9dc53e62e55e64644766946d1be381242fd41a5e6bb64c07e0e2119

Contents?: true

Size: 1.04 KB

Versions: 2

Compression:

Stored size: 1.04 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", /device_model/, "#{model_name}"
      #sleep 1 # ensure scripts have different timestamps
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
old_sql-1.45.0 lib/generators/old_sql/install_migrations_generator.rb
old_sql-1.44.0 lib/generators/old_sql/install_migrations_generator.rb