2022-04-21 23:44:05 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-05-18 14:15:20 +00:00
|
|
|
ENV['DB'] ||= 'postgres'
|
2022-04-21 23:44:05 +00:00
|
|
|
|
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
|
|
|
|
2022-05-18 14:25:02 +00:00
|
|
|
case ENV.fetch('DB')
|
2022-04-21 23:44:05 +00:00
|
|
|
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'
|
|
|
|
|
2022-05-18 13:40:21 +00:00
|
|
|
client = PG::Connection.new(host: conn_params[:host], password: '', user: :postgres)
|
2022-05-18 13:11:38 +00:00
|
|
|
|
|
|
|
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)
|