1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/activerecord/Rakefile

143 lines
4.7 KiB
Text
Raw Normal View History

# frozen_string_literal: true
require "rake/testtask"
require_relative "test/config"
require_relative "test/support/config"
def run_without_aborting(*tasks)
errors = []
tasks.each do |task|
Rake::Task[task].invoke
rescue Exception
errors << task
end
abort "Errors running #{errors.join(', ')}" if errors.any?
end
desc "Run mysql2, sqlite, and postgresql tests by default"
2016-08-06 13:37:57 -04:00
task default: :test
task :package
desc "Run mysql2, sqlite, and postgresql tests"
task :test do
tasks = defined?(JRUBY_VERSION) ?
%w(test_jdbcmysql test_jdbcsqlite3 test_jdbcpostgresql) :
2015-12-15 17:01:30 -05:00
%w(test_mysql2 test_sqlite3 test_postgresql)
run_without_aborting(*tasks)
end
namespace :test do
task :isolated do
tasks = defined?(JRUBY_VERSION) ?
%w(isolated_test_jdbcmysql isolated_test_jdbcsqlite3 isolated_test_jdbcpostgresql) :
2015-12-15 17:01:30 -05:00
%w(isolated_test_mysql2 isolated_test_sqlite3 isolated_test_postgresql)
run_without_aborting(*tasks)
end
end
namespace :db do
desc "Build MySQL and PostgreSQL test databases"
2016-08-06 13:37:57 -04:00
task create: ["db:mysql:build", "db:postgresql:build"]
desc "Drop MySQL and PostgreSQL test databases"
2016-08-06 13:37:57 -04:00
task drop: ["db:mysql:drop", "db:postgresql:drop"]
end
2015-12-15 17:01:30 -05:00
%w( mysql2 postgresql sqlite3 sqlite3_mem db2 oracle jdbcmysql jdbcpostgresql jdbcsqlite3 jdbcderby jdbch2 jdbchsqldb ).each do |adapter|
namespace :test do
Rake::TestTask.new(adapter => "#{adapter}:env") { |t|
adapter_short = adapter == "db2" ? adapter : adapter[/^[a-z0-9]+/]
t.libs << "test"
t.test_files = (Dir.glob("test/cases/**/*_test.rb").reject {
|x| x.include?("/adapters/")
} + Dir.glob("test/cases/adapters/#{adapter_short}/**/*_test.rb"))
t.warning = true
t.verbose = true
t.ruby_opts = ["--dev"] if defined?(JRUBY_VERSION)
}
namespace :isolated do
task adapter => "#{adapter}:env" do
adapter_short = adapter == "db2" ? adapter : adapter[/^[a-z0-9]+/]
puts [adapter, adapter_short].inspect
(Dir["test/cases/**/*_test.rb"].reject {
|x| x.include?("/adapters/")
} + Dir["test/cases/adapters/#{adapter_short}/**/*_test.rb"]).all? do |file|
sh(Gem.ruby, "-w", "-Itest", file)
end || raise("Failures")
end
end
2009-05-13 04:06:53 -04:00
end
namespace adapter do
2016-08-06 13:37:57 -04:00
task test: "test_#{adapter}"
task isolated_test: "isolated_test_#{adapter}"
# Set the connection environment for the adapter
task(:env) { ENV["ARCONN"] = adapter }
end
# Make sure the adapter test evaluates the env setting task
task "test_#{adapter}" => ["#{adapter}:env", "test:#{adapter}"]
task "isolated_test_#{adapter}" => ["#{adapter}:env", "test:isolated:#{adapter}"]
end
namespace :db do
namespace :mysql do
desc "Build the MySQL test databases"
task :build do
config = ARTest.config["connections"]["mysql2"]
Use utf8mb4 character set by default for MySQL database (#33608) * Use utf8mb4 character set by default `utf8mb4` character set supports supplementary characters including emoji. `utf8` character set with 3-Byte encoding is not enough to support them. There was a downside of 4-Byte length character set with MySQL 5.5 and 5.6: "ERROR 1071 (42000): Specified key was too long; max key length is 767 bytes" for Rails string data type which is mapped to varchar(255) type. MySQL 5.7 supports 3072 byte key prefix length by default. * Remove `DEFAULT COLLATE` from Active Record unit test databases There should be no "one size fits all" collation in MySQL 5.7. Let MySQL server choose the default collation for Active Record unit test databases. Users can choose their best collation for their databases by setting `options[:collation]` based on their requirements. * InnoDB FULLTEXT indexes support since MySQL 5.6 it does not have to use MyISAM storage engine whose maximum key length is 1000 bytes. Using MyISAM storag engine with utf8mb4 character set would cause "Specified key was too long; max key length is 1000 bytes" https://dev.mysql.com/doc/refman/5.6/en/innodb-fulltext-index.html * References "10.9.1 The utf8mb4 Character Set (4-Byte UTF-8 Unicode Encoding)" https://dev.mysql.com/doc/refman/5.7/en/charset-unicode-utf8mb4.html "10.9.2 The utf8mb3 Character Set (3-Byte UTF-8 Unicode Encoding)" https://dev.mysql.com/doc/refman/5.7/en/charset-unicode-utf8.html "14.8.1.7 Limits on InnoDB Tables" https://dev.mysql.com/doc/refman/5.7/en/innodb-restrictions.html > If innodb_large_prefix is enabled (the default), the index key prefix limit is 3072 bytes > for InnoDB tables that use DYNAMIC or COMPRESSED row format. * CI against MySQL 5.7 Followed this instruction and changed root password to empty string. https://docs.travis-ci.com/user/database-setup/#MySQL-57 * The recommended minimum version of MySQL is 5.7.9 to support utf8mb4 character set and `innodb_default_row_format` MySQL 5.7.9 introduces `innodb_default_row_format` to support 3072 byte length index by default. Users do not have to change MySQL database configuration to support Rails string type. https://dev.mysql.com/doc/refman/5.7/en/innodb-parameters.html#sysvar_innodb_default_row_format https://dev.mysql.com/doc/refman/5.7/en/innodb-restrictions.html > If innodb_large_prefix is enabled (the default), > the index key prefix limit is 3072 bytes for InnoDB tables that use DYNAMIC or COMPRESSED row format. * The recommended minimum version of MariaDB is 10.2.2 MariaDB 10.2.2 is the first version of MariaDB supporting `innodb_default_row_format` Also MariaDB says "MySQL 5.7 is compatible with MariaDB 10.2". - innodb_default_row_format https://mariadb.com/kb/en/library/xtradbinnodb-server-system-variables/#innodb_default_row_format - "MariaDB versus MySQL - Compatibility" https://mariadb.com/kb/en/library/mariadb-vs-mysql-compatibility/ > MySQL 5.7 is compatible with MariaDB 10.2 - "Supported Character Sets and Collations" https://mariadb.com/kb/en/library/supported-character-sets-and-collations/
2018-09-11 16:03:34 -04:00
%x( mysql --user=#{config["arunit"]["username"]} --password=#{config["arunit"]["password"]} -e "create DATABASE #{config["arunit"]["database"]} DEFAULT CHARACTER SET utf8mb4" )
%x( mysql --user=#{config["arunit2"]["username"]} --password=#{config["arunit2"]["password"]} -e "create DATABASE #{config["arunit2"]["database"]} DEFAULT CHARACTER SET utf8mb4" )
end
desc "Drop the MySQL test databases"
task :drop do
config = ARTest.config["connections"]["mysql2"]
%x( mysqladmin --user=#{config["arunit"]["username"]} --password=#{config["arunit"]["password"]} -f drop #{config["arunit"]["database"]} )
%x( mysqladmin --user=#{config["arunit2"]["username"]} --password=#{config["arunit2"]["password"]} -f drop #{config["arunit2"]["database"]} )
end
desc "Rebuild the MySQL test databases"
2016-08-06 13:37:57 -04:00
task rebuild: [:drop, :build]
end
namespace :postgresql do
desc "Build the PostgreSQL test databases"
task :build do
config = ARTest.config["connections"]["postgresql"]
%x( createdb -E UTF8 -T template0 #{config["arunit"]["database"]} )
%x( createdb -E UTF8 -T template0 #{config["arunit2"]["database"]} )
end
desc "Drop the PostgreSQL test databases"
task :drop do
config = ARTest.config["connections"]["postgresql"]
%x( dropdb #{config["arunit"]["database"]} )
%x( dropdb #{config["arunit2"]["database"]} )
end
desc "Rebuild the PostgreSQL test databases"
2016-08-06 13:37:57 -04:00
task rebuild: [:drop, :build]
end
end
2016-08-06 13:37:57 -04:00
task build_mysql_databases: "db:mysql:build"
task drop_mysql_databases: "db:mysql:drop"
task rebuild_mysql_databases: "db:mysql:rebuild"
2016-08-06 13:37:57 -04:00
task build_postgresql_databases: "db:postgresql:build"
task drop_postgresql_databases: "db:postgresql:drop"
task rebuild_postgresql_databases: "db:postgresql:rebuild"
task :lines do
load File.expand_path("../tools/line_statistics", __dir__)
files = FileList["lib/active_record/**/*.rb"]
CodeTools::LineStatistics.new(files).print_loc
end