2022-04-21 23:44:05 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
ENV['DB'] ||= 'mysql'
|
|
|
|
|
2022-05-18 13:11:38 +00:00
|
|
|
conn_params = { database: :rating_test, host: '127.0.0.1' }
|
2022-04-21 23:44:05 +00:00
|
|
|
|
|
|
|
case ENV.fetch('DB', nil)
|
|
|
|
when 'mysql'
|
2022-05-18 13:11:38 +00:00
|
|
|
require 'mysql2'
|
|
|
|
|
|
|
|
client = Mysql2::Client.new(host: conn_params[:host], username: :root)
|
|
|
|
|
2022-04-21 23:44:05 +00:00
|
|
|
conn_params[:adapter] = :mysql2
|
|
|
|
conn_params[:username] = :root
|
|
|
|
when 'postgres'
|
2022-05-18 13:11:38 +00:00
|
|
|
require 'pg'
|
|
|
|
|
|
|
|
client = PG::Connection.new(host: conn_params[:host], user: :postgres)
|
|
|
|
|
|
|
|
conn_params[:adapter] = :postgresql
|
|
|
|
conn_params[:username] = :postgres
|
2022-04-21 23:44:05 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
client.query('DROP DATABASE IF EXISTS rating_test;')
|
|
|
|
client.query('CREATE DATABASE rating_test;')
|
|
|
|
|
|
|
|
ActiveRecord::Base.establish_connection(conn_params)
|