Sha256: 14e3cf9063889e4bc58c6086b5846833b60ce9ee7da9357c9d431b2d9d4bfe9f

Contents?: true

Size: 1.41 KB

Versions: 17

Compression:

Stored size: 1.41 KB

Contents

# frozen_string_literal: true

require "rails/command"
require "rails/commands/dbconsole/dbconsole_command"

class Rails::Command::DbconsoleCommand < Rails::Command::Base
  class_option :server, type: :string, desc: "Specifies the server to use."

  def perform
    require "rake"
    Rake.with_application(&:load_rakefile) # Needed to initialize Rails.application
    Rails::DBConsole.start(options)
  end
end

class Rails::DBConsole
  DBConfig = Struct.new(:configuration_hash, :adapter, :database)

  private

  def db_config
    @db_config ||= DBConfig.new(configuration_hash, adapter, database)
  end

  def configuration_hash
    return @configuration_hash if defined?(@configuration_hash)

    rails_db_config = Rails.application.config.database_configuration

    sequel_configuration = SequelRails::Configuration.new
    SequelRails.configuration = sequel_configuration.merge!(raw: rails_db_config)

    storage = SequelRails::Storage.adapter_for(Rails.env)
    config = storage.config.with_indifferent_access

    if @options[:server]
      server_config = config.fetch(:servers).fetch(@options[:server])
      config.merge!(server_config)
    end

    @configuration_hash = config
  end

  def adapter
    mapping = SequelRails::DbConfig::ADAPTER_MAPPING.invert
    value = configuration_hash.fetch(:adapter)
    mapping[value] || value
  end

  def database
    @options[:database] || configuration_hash.fetch(:database)
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
umbrellio-sequel-plugins-0.14.0.192 lib/umbrellio_sequel_plugins/rails_db_command.rb
umbrellio-sequel-plugins-0.14.0.189 lib/umbrellio_sequel_plugins/rails_db_command.rb
umbrellio-sequel-plugins-0.14.0.188 lib/umbrellio_sequel_plugins/rails_db_command.rb
umbrellio-sequel-plugins-0.14.0.187 lib/umbrellio_sequel_plugins/rails_db_command.rb
umbrellio-sequel-plugins-0.14.0 lib/umbrellio_sequel_plugins/rails_db_command.rb
umbrellio-sequel-plugins-0.13.0.185 lib/umbrellio_sequel_plugins/rails_db_command.rb
umbrellio-sequel-plugins-0.13.0.172 lib/umbrellio_sequel_plugins/rails_db_command.rb
umbrellio-sequel-plugins-0.13.0 lib/umbrellio_sequel_plugins/rails_db_command.rb
umbrellio-sequel-plugins-0.12.0.169 lib/umbrellio_sequel_plugins/rails_db_command.rb
umbrellio-sequel-plugins-0.12.0 lib/umbrellio_sequel_plugins/rails_db_command.rb
umbrellio-sequel-plugins-0.12.0.159 lib/umbrellio_sequel_plugins/rails_db_command.rb
umbrellio-sequel-plugins-0.11.0.143 lib/umbrellio_sequel_plugins/rails_db_command.rb
umbrellio-sequel-plugins-0.10.0.101 lib/umbrellio_sequel_plugins/rails_db_command.rb
umbrellio-sequel-plugins-0.10.0.100 lib/umbrellio_sequel_plugins/rails_db_command.rb
umbrellio-sequel-plugins-0.10.0.86 lib/umbrellio_sequel_plugins/rails_db_command.rb
umbrellio-sequel-plugins-0.9.0.79 lib/umbrellio_sequel_plugins/rails_db_command.rb
umbrellio-sequel-plugins-0.9.0.76 lib/umbrellio_sequel_plugins/rails_db_command.rb