Sha256: d384ad82f993946a7fefefbc5ab9889012271db9ed4d17a0e6195bc7fef590b7

Contents?: true

Size: 1.41 KB

Versions: 9

Compression:

Stored size: 1.41 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, spec_name = nil)
      environments = [environment]
      environments << 'test' if environment == 'development'

      environments.each do |env|
        ActiveRecord::Base.configurations.configs_for(env_name: env).each do |db_config|
          next if spec_name && spec_name != db_config.spec_name

          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

9 entries across 9 versions & 2 rubygems

Version Path
activerecord-jdbc-alt-adapter-60.3.0-java lib/arjdbc/tasks/databases.rake
activerecord-jdbc-alt-adapter-60.2.0-java lib/arjdbc/tasks/databases.rake
activerecord-jdbc-adapter-60.4-java lib/arjdbc/tasks/databases.rake
activerecord-jdbc-alt-adapter-60.1.0-java lib/arjdbc/tasks/databases.rake
activerecord-jdbc-adapter-60.3-java lib/arjdbc/tasks/databases.rake
activerecord-jdbc-adapter-60.2-java lib/arjdbc/tasks/databases.rake
activerecord-jdbc-alt-adapter-60.0.0-java lib/arjdbc/tasks/databases.rake
activerecord-jdbc-adapter-60.1-java lib/arjdbc/tasks/databases.rake
activerecord-jdbc-adapter-60.0-java lib/arjdbc/tasks/databases.rake