From 7ac7f4a18895da2aba093f603c968a630c5fe4ba Mon Sep 17 00:00:00 2001 From: Alberto Almagro Date: Sat, 18 Nov 2017 11:54:18 +0100 Subject: Remove default ENGINE=InnoDB for Mysql2 adapter Before this commit ENGINE=InnoDB was added by default to Mysql2 adapter +create_table+ if no +options+ option was provided. This default ENGINE was lost as soon as something was passed in at +options+ option, making its goal and propagation inconsistent, as the programmer needed to remember including ENGINE=InnoDB when something was passed in. This commit removes default ENGINE as its use isn't needed anymore for current MySQL and MariaDB versions. It adds compatibility support and tests to ensure that default ENGINE is still present for migrations with version 5.1 and before. It also ensures we still dump the ENGINE option to +schema.rb+ in order to avoid inconsistencies. --- .../active_record/connection_adapters/abstract_mysql_adapter.rb | 2 +- activerecord/lib/active_record/migration/compatibility.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'activerecord/lib/active_record') diff --git a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb index 479131caad..2d1d265f65 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb @@ -293,7 +293,7 @@ module ActiveRecord end def create_table(table_name, **options) #:nodoc: - super(table_name, options: "ENGINE=InnoDB", **options) + super(table_name, options: "", **options) end def bulk_change_table(table_name, operations) #:nodoc: diff --git a/activerecord/lib/active_record/migration/compatibility.rb b/activerecord/lib/active_record/migration/compatibility.rb index bd8c054c28..7ae8073478 100644 --- a/activerecord/lib/active_record/migration/compatibility.rb +++ b/activerecord/lib/active_record/migration/compatibility.rb @@ -28,6 +28,14 @@ module ActiveRecord super end end + + def create_table(table_name, options = {}) + if adapter_name == "Mysql2" + super(table_name, options: "ENGINE=InnoDB", **options) + else + super + end + end end class V5_0 < V5_1 -- cgit v1.2.3