up: avoids user and password for local tests

The `require` now is local avoiding require unnecessary driver.
main
Washington Botelho 2022-05-18 10:11:38 -03:00
parent 2985636b66
commit 277c0c08f3
1 changed files with 11 additions and 17 deletions

View File

@ -1,30 +1,24 @@
# frozen_string_literal: true # frozen_string_literal: true
require 'mysql2'
require 'pg'
ENV['DB'] ||= 'mysql' ENV['DB'] ||= 'mysql'
conn_params = { conn_params = { database: :rating_test, host: '127.0.0.1' }
database: :rating_test,
host: '127.0.0.1',
}
case ENV.fetch('DB', nil) case ENV.fetch('DB', nil)
when 'mysql' 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[:adapter] = :mysql2
conn_params[:username] = :root conn_params[:username] = :root
when 'postgres' when 'postgres'
ENV['POSTGRES_USER'] ||= 'rating_user' require 'pg'
client = PG::Connection.new(host: '127.0.0.1', user: ENV.fetch('POSTGRES_USER', nil),
password: ENV.fetch('POSTGRES_PASSWORD', nil) client = PG::Connection.new(host: conn_params[:host], user: :postgres)
)
conn_params.merge!( conn_params[:adapter] = :postgresql
adapter: :postgresql, conn_params[:username] = :postgres
username: ENV.fetch('POSTGRES_USER', nil),
password: ENV.fetch('POSTGRES_PASSWORD', nil)
)
end end
client.query('DROP DATABASE IF EXISTS rating_test;') client.query('DROP DATABASE IF EXISTS rating_test;')