Flowdock
method

copy

Importance_0
v3.1.0 - Show latest stable - 0 notes - Class: ActiveRecord::Migration
copy(destination, sources, options = {}) public

No documentation

This method has no description. You can help the Ruby on Rails community by adding new notes.

Hide source
# File activerecord/lib/active_record/migration.rb, line 451
    def copy(destination, sources, options = {})
      copied = []

      FileUtils.mkdir_p(destination) unless File.exists?(destination)

      destination_migrations = ActiveRecord::Migrator.migrations(destination)
      last = destination_migrations.last
      sources.each do |name, path|
        source_migrations = ActiveRecord::Migrator.migrations(path)

        source_migrations.each do |migration|
          source = File.read(migration.filename)
          source = "# This migration comes from #{name} (originally #{migration.version})\n#{source}"

          if duplicate = destination_migrations.detect { |m| m.name == migration.name }
            options[:on_skip].call(name, migration) if File.read(duplicate.filename) != source && options[:on_skip]
            next
          end

          migration.version = next_migration_number(last ? last.version + 1 : 0).to_i
          new_path = File.join(destination, "#{migration.version}_#{migration.name.underscore}.rb")
          old_path, migration.filename = migration.filename, new_path
          last = migration

          FileUtils.cp(old_path, migration.filename)
          copied << migration
          options[:on_copy].call(name, migration, old_path) if options[:on_copy]
          destination_migrations << migration
        end
      end

      copied
    end
Register or log in to add new notes.