Skip to content

Commit cdb8957

Browse files
committed
Factor out valid_column_definition_options
Shopify is implementing a custom ActiveRecord adapter to integrate with [Vitess](https://vitess.io/), and we would like to overload the `valid_{column,table}_definition_options` methods and add additional valid options for schema migrations. For example: ```ruby module ActiveRecord module ConnectionAdapters class VitessMysql2Adapter < Mysql2Adapter ... def valid_table_definition_options super + [:skip_vschema_migrations, :sharding_keys, :auto_increment] end def valid_column_definition_options super + [:skip_vschema_migrations, :sharding_keys, :auto_increment] end end end end ``` This is the simplest possible change and factors out the various `valid_{table,column,primary_key}_definition_options` to be a public method on an adapter instance.
1 parent 65ae7d1 commit cdb8957

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ def new_check_constraint_definition(expression, options) # :nodoc:
586586

587587
private
588588
def valid_column_definition_options
589-
ColumnDefinition::OPTION_NAMES
589+
@conn.valid_column_definition_options
590590
end
591591

592592
def create_column_definition(name, type, options)

activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1497,6 +1497,18 @@ def bulk_change_table(table_name, operations) # :nodoc:
14971497
non_combinable_operations.each(&:call)
14981498
end
14991499

1500+
def valid_table_definition_options
1501+
[:temporary, :if_not_exists, :options, :as, :comment, :charset, :collation]
1502+
end
1503+
1504+
def valid_column_definition_options
1505+
ColumnDefinition::OPTION_NAMES
1506+
end
1507+
1508+
def valid_primary_key_options
1509+
[:limit, :default, :precision]
1510+
end
1511+
15001512
private
15011513
def validate_change_column_null_argument!(value)
15021514
unless value == true || value == false
@@ -1595,14 +1607,6 @@ def create_alter_table(name)
15951607
AlterTable.new create_table_definition(name)
15961608
end
15971609

1598-
def valid_table_definition_options
1599-
[:temporary, :if_not_exists, :options, :as, :comment, :charset, :collation]
1600-
end
1601-
1602-
def valid_primary_key_options
1603-
[:limit, :default, :precision]
1604-
end
1605-
16061610
def validate_create_table_options!(options)
16071611
unless options[:_skip_validate_options]
16081612
options

0 commit comments

Comments
 (0)