Sha256: 19dcbeff99851c431e778d4a2dc520a3ab9b783de9e00e1147c8b6396ca9df10

Contents?: true

Size: 1.18 KB

Versions: 1

Compression:

Stored size: 1.18 KB

Contents

# frozen_string_literal: true

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

class Rails::Command::DbconsoleCommand < Rails::Command::Base
  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)
    @configuration_hash = storage.config.with_indifferent_access
  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

1 entries across 1 versions & 1 rubygems

Version Path
umbrellio-sequel-plugins-0.8.0.73 lib/umbrellio_sequel_plugins/rails_db_command.rb