up: avoids user and password for local tests
The `require` now is local avoiding require unnecessary driver.main
parent
2985636b66
commit
277c0c08f3
|
@ -1,30 +1,24 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'mysql2'
|
||||
require 'pg'
|
||||
|
||||
ENV['DB'] ||= 'mysql'
|
||||
|
||||
conn_params = {
|
||||
database: :rating_test,
|
||||
host: '127.0.0.1',
|
||||
}
|
||||
conn_params = { database: :rating_test, host: '127.0.0.1' }
|
||||
|
||||
case ENV.fetch('DB', nil)
|
||||
when 'mysql'
|
||||
client = Mysql2::Client.new(host: '127.0.0.1', username: :root)
|
||||
require 'mysql2'
|
||||
|
||||
client = Mysql2::Client.new(host: conn_params[:host], username: :root)
|
||||
|
||||
conn_params[:adapter] = :mysql2
|
||||
conn_params[:username] = :root
|
||||
when 'postgres'
|
||||
ENV['POSTGRES_USER'] ||= 'rating_user'
|
||||
client = PG::Connection.new(host: '127.0.0.1', user: ENV.fetch('POSTGRES_USER', nil),
|
||||
password: ENV.fetch('POSTGRES_PASSWORD', nil)
|
||||
)
|
||||
conn_params.merge!(
|
||||
adapter: :postgresql,
|
||||
username: ENV.fetch('POSTGRES_USER', nil),
|
||||
password: ENV.fetch('POSTGRES_PASSWORD', nil)
|
||||
)
|
||||
require 'pg'
|
||||
|
||||
client = PG::Connection.new(host: conn_params[:host], user: :postgres)
|
||||
|
||||
conn_params[:adapter] = :postgresql
|
||||
conn_params[:username] = :postgres
|
||||
end
|
||||
|
||||
client.query('DROP DATABASE IF EXISTS rating_test;')
|
||||
|
|
Loading…
Reference in New Issue