diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2018-11-09 05:37:20 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2018-11-09 05:49:44 +0900 |
commit | b04c6339640d87b680f1975f3686fed0d885b1bc (patch) | |
tree | ae5b24f0af4f23fa2d2f118d65c76b740c5d3e0d | |
parent | 56128abcbab9b4d9ecd5d03612f7cf3901dd65b0 (diff) | |
download | rails-b04c6339640d87b680f1975f3686fed0d885b1bc.tar.gz rails-b04c6339640d87b680f1975f3686fed0d885b1bc.tar.bz2 rails-b04c6339640d87b680f1975f3686fed0d885b1bc.zip |
Refactor to initialize `TableDefinition` by kwargs
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb | 10 | ||||
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb | 8 |
2 files changed, 14 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb index ca99a2d983..b531ad5375 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb @@ -259,7 +259,15 @@ module ActiveRecord attr_accessor :indexes attr_reader :name, :temporary, :if_not_exists, :options, :as, :foreign_keys, :comment - def initialize(name, temporary = false, if_not_exists = false, options = nil, as = nil, comment: nil) + def initialize( + name, + temporary: false, + if_not_exists: false, + options: nil, + as: nil, + comment: nil, + ** + ) @columns_hash = {} @indexes = [] @foreign_keys = [] diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb index 295ad89f7c..38cfc3a241 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb @@ -290,8 +290,8 @@ module ActiveRecord # SELECT * FROM orders INNER JOIN line_items ON order_id=orders.id # # See also TableDefinition#column for details on how to create columns. - def create_table(table_name, comment: nil, **options) - td = create_table_definition table_name, options[:temporary], options[:if_not_exists], options[:options], options[:as], comment: comment + def create_table(table_name, **options) + td = create_table_definition(table_name, options) if options[:id] != false && !options[:as] pk = options.fetch(:primary_key) do @@ -320,7 +320,9 @@ module ActiveRecord end if supports_comments? && !supports_comments_in_create? - change_table_comment(table_name, comment) if comment.present? + if table_comment = options[:comment].presence + change_table_comment(table_name, table_comment) + end td.columns.each do |column| change_column_comment(table_name, column.name, column.comment) if column.comment.present? |