Fix database configuration and generation

I tried using the same config for mysql2 and trilogy but instead it
eneded up breaking the trilogy tests - they were only running in mysql2
mode. I wanted to do this so that the rake tasks for trilogy wouldn't
need to be duplicated but since that didn't work out quite right, I've
decide to duplicate the calls and add if exists / if not exists where
applicable. The configs should be the same but this will make sure that
if they do deviate, the dbs are always created/dropped.
This commit is contained in:
eileencodes 2023-04-19 15:34:32 -04:00
parent 484dcb6538
commit 756cea1b6d
No known key found for this signature in database
GPG Key ID: BA5C575120BBE8DF
2 changed files with 88 additions and 49 deletions

@ -209,11 +209,20 @@ end
namespace :db do
namespace :mysql do
connection_arguments = lambda do |connection_name|
config = ARTest.config["connections"]["mysql2"][connection_name]
["--user=#{config["username"]}", ("--password=#{config["password"]}" if config["password"]), ("--host=#{config["host"]}" if config["host"]), ("--socket=#{config["socket"]}" if config["socket"])].join(" ")
mysql2_config = ARTest.config["connections"]["mysql2"]
mysql2_connection_arguments = lambda do |connection_name|
mysql2_connection = mysql2_config[connection_name]
["--user=#{mysql2_connection["username"]}", ("--password=#{mysql2_connection["password"]}" if mysql2_connection["password"]), ("--host=#{mysql2_connection["host"]}" if mysql2_connection["host"]), ("--socket=#{mysql2_connection["socket"]}" if mysql2_connection["socket"])].join(" ")
end
trilogy_config = ARTest.config["connections"]["trilogy"]
trilogy_connection_arguments = lambda do |connection_name|
trilogy_connection = trilogy_config[connection_name]
["--user=#{trilogy_connection["username"]}", ("--password=#{trilogy_connection["password"]}" if trilogy_connection["password"]), ("--host=#{trilogy_connection["host"]}" if trilogy_connection["host"]), ("--socket=#{trilogy_connection["socket"]}" if trilogy_connection["socket"])].join(" ")
end
mysql_configs = [mysql2_config, trilogy_config]
desc "Create the MySQL Rails User"
task :build_user do
if ENV["MYSQL_CODESPACES"]
@ -226,26 +235,30 @@ namespace :db do
mysql_command = "mysql -uroot -e"
end
config = ARTest.config["connections"]["mysql2"]
%x( #{mysql_command} "CREATE USER IF NOT EXISTS '#{config["arunit"]["username"]}'@'localhost';" )
%x( #{mysql_command} "CREATE USER IF NOT EXISTS '#{config["arunit2"]["username"]}'@'localhost';" )
%x( #{mysql_command} "GRANT ALL PRIVILEGES ON #{config["arunit"]["database"]}.* to '#{config["arunit"]["username"]}'@'localhost'" )
%x( #{mysql_command} "GRANT ALL PRIVILEGES ON #{config["arunit2"]["database"]}.* to '#{config["arunit2"]["username"]}'@'localhost'" )
%x( #{mysql_command} "GRANT ALL PRIVILEGES ON inexistent_activerecord_unittest.* to '#{config["arunit"]["username"]}'@'localhost';" )
mysql_configs.each do |config|
%x( #{mysql_command} "CREATE USER IF NOT EXISTS '#{config["arunit"]["username"]}'@'localhost';" )
%x( #{mysql_command} "CREATE USER IF NOT EXISTS '#{config["arunit2"]["username"]}'@'localhost';" )
%x( #{mysql_command} "GRANT ALL PRIVILEGES ON #{config["arunit"]["database"]}.* to '#{config["arunit"]["username"]}'@'localhost'" )
%x( #{mysql_command} "GRANT ALL PRIVILEGES ON #{config["arunit2"]["database"]}.* to '#{config["arunit2"]["username"]}'@'localhost'" )
%x( #{mysql_command} "GRANT ALL PRIVILEGES ON inexistent_activerecord_unittest.* to '#{config["arunit"]["username"]}'@'localhost';" )
end
end
desc "Build the MySQL test databases"
task build: ["db:mysql:build_user"] do
config = ARTest.config["connections"]["mysql2"]
%x( mysql #{connection_arguments["arunit"]} -e "create DATABASE #{config["arunit"]["database"]} DEFAULT CHARACTER SET utf8mb4" )
%x( mysql #{connection_arguments["arunit2"]} -e "create DATABASE #{config["arunit2"]["database"]} DEFAULT CHARACTER SET utf8mb4" )
%x( mysql #{mysql2_connection_arguments["arunit"]} -e "create DATABASE IF NOT EXISTS #{mysql2_config["arunit"]["database"]} DEFAULT CHARACTER SET utf8mb4" )
%x( mysql #{mysql2_connection_arguments["arunit2"]} -e "create DATABASE IF NOT EXISTS #{mysql2_config["arunit2"]["database"]} DEFAULT CHARACTER SET utf8mb4" )
%x( mysql #{trilogy_connection_arguments["arunit"]} -e "create DATABASE IF NOT EXISTS #{trilogy_config["arunit"]["database"]} DEFAULT CHARACTER SET utf8mb4" )
%x( mysql #{trilogy_connection_arguments["arunit2"]} -e "create DATABASE IF NOT EXISTS #{trilogy_config["arunit2"]["database"]} DEFAULT CHARACTER SET utf8mb4" )
end
desc "Drop the MySQL test databases"
task :drop do
config = ARTest.config["connections"]["mysql2"]
%x( mysqladmin #{connection_arguments["arunit"]} -f drop #{config["arunit"]["database"]} )
%x( mysqladmin #{connection_arguments["arunit2"]} -f drop #{config["arunit2"]["database"]} )
%x( mysql #{mysql2_connection_arguments["arunit"]} -e "drop database IF EXISTS #{mysql2_config["arunit"]["database"]}" )
%x( mysql #{mysql2_connection_arguments["arunit2"]} -e "drop database IF EXISTS #{mysql2_config["arunit2"]["database"]}" )
%x( mysql #{trilogy_connection_arguments["arunit"]} -e "drop database IF EXISTS #{trilogy_config["arunit"]["database"]}" )
%x( mysql #{trilogy_connection_arguments["arunit2"]} -e "drop database IF EXISTS #{trilogy_config["arunit2"]["database"]}" )
end
desc "Rebuild the MySQL test databases"

@ -1,37 +1,5 @@
default_connection: <%= defined?(JRUBY_VERSION) ? 'jdbcsqlite3' : 'sqlite3' %>
mysql: &mysql
arunit:
username: rails
encoding: utf8mb4
collation: utf8mb4_unicode_ci
<% if ENV['MYSQL_PREPARED_STATEMENTS'] %>
prepared_statements: true
<% else %>
prepared_statements: false
<% end %>
<% if ENV['MYSQL_HOST'] %>
host: <%= ENV['MYSQL_HOST'] %>
<% end %>
<% if ENV['MYSQL_SOCK'] %>
socket: "<%= ENV['MYSQL_SOCK'] %>"
<% end %>
arunit2:
username: rails
encoding: utf8mb4
collation: utf8mb4_general_ci
<% if ENV['MYSQL_PREPARED_STATEMENTS'] %>
prepared_statements: true
<% else %>
prepared_statements: false
<% end %>
<% if ENV['MYSQL_HOST'] %>
host: <%= ENV['MYSQL_HOST'] %>
<% end %>
<% if ENV['MYSQL_SOCK'] %>
socket: "<%= ENV['MYSQL_SOCK'] %>"
<% end %>
connections:
jdbcderby:
arunit: activerecord_unittest
@ -68,7 +36,36 @@ connections:
timeout: 5000
mysql2:
<<: *mysql
arunit:
username: rails
encoding: utf8mb4
collation: utf8mb4_unicode_ci
<% if ENV['MYSQL_PREPARED_STATEMENTS'] %>
prepared_statements: true
<% else %>
prepared_statements: false
<% end %>
<% if ENV['MYSQL_HOST'] %>
host: <%= ENV['MYSQL_HOST'] %>
<% end %>
<% if ENV['MYSQL_SOCK'] %>
socket: "<%= ENV['MYSQL_SOCK'] %>"
<% end %>
arunit2:
username: rails
encoding: utf8mb4
collation: utf8mb4_general_ci
<% if ENV['MYSQL_PREPARED_STATEMENTS'] %>
prepared_statements: true
<% else %>
prepared_statements: false
<% end %>
<% if ENV['MYSQL_HOST'] %>
host: <%= ENV['MYSQL_HOST'] %>
<% end %>
<% if ENV['MYSQL_SOCK'] %>
socket: "<%= ENV['MYSQL_SOCK'] %>"
<% end %>
oracle:
arunit:
@ -112,4 +109,33 @@ connections:
database: ':memory:'
trilogy:
<<: *mysql
arunit:
username: rails
encoding: utf8mb4
collation: utf8mb4_unicode_ci
<% if ENV['MYSQL_PREPARED_STATEMENTS'] %>
prepared_statements: true
<% else %>
prepared_statements: false
<% end %>
<% if ENV['MYSQL_HOST'] %>
host: <%= ENV['MYSQL_HOST'] %>
<% end %>
<% if ENV['MYSQL_SOCK'] %>
socket: "<%= ENV['MYSQL_SOCK'] %>"
<% end %>
arunit2:
username: rails
encoding: utf8mb4
collation: utf8mb4_general_ci
<% if ENV['MYSQL_PREPARED_STATEMENTS'] %>
prepared_statements: true
<% else %>
prepared_statements: false
<% end %>
<% if ENV['MYSQL_HOST'] %>
host: <%= ENV['MYSQL_HOST'] %>
<% end %>
<% if ENV['MYSQL_SOCK'] %>
socket: "<%= ENV['MYSQL_SOCK'] %>"
<% end %>