Sha256: 67161d2993fd5563260688abcca95cd7ad9d567f1e818fc9d77343bc76cbb2ef

Contents?: true

Size: 1.33 KB

Versions: 1

Compression:

Stored size: 1.33 KB

Contents

require 'arjdbc/tasks/database_tasks'

module ActiveRecord::Tasks

  DatabaseTasks.module_eval do

    # @override patched to adapt jdbc configuration
    def each_current_configuration(environment)
      environments = [environment]
      environments << 'test' if environment == 'development'

      environments.each do |env|
        ActiveRecord::Base.configurations.configs_for(env_name: env).each do |db_config|
          yield adapt_jdbc_config(db_config.config), db_config.spec_name, env unless db_config.config['database'].blank?
        end
      end
    end

    # @override patched to adapt jdbc configuration
    def each_local_configuration
      ActiveRecord::Base.configurations.configs_for.each do |db_config|
        next unless db_config.config['database']

        if local_database?(db_config.config)
          yield adapt_jdbc_config(db_config.config)
        else
          $stderr.puts "This task only modifies local databases. #{db_config.config['database']} is on a remote host."
        end
      end
    end

    private

    def adapt_jdbc_config(config)
      return config unless config['adapter']
      config.merge 'adapter' => config['adapter'].sub(/^jdbc/, '')
    end

  end

  MySQLDatabaseTasks.class_eval do

    def error_class
      ActiveRecord::JDBCError
    end

  end if const_defined?(:MySQLDatabaseTasks)

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
activerecord-jdbc-adapter-60.0.rc1-java lib/arjdbc/tasks/databases.rake