Skip to content

Comments

Factor out the valid_column_definition_options method to AbstractAdapter class#47609

Merged
eileencodes merged 1 commit intorails:mainfrom
Shopify:factor-out-column-def
Mar 9, 2023
Merged

Factor out the valid_column_definition_options method to AbstractAdapter class#47609
eileencodes merged 1 commit intorails:mainfrom
Shopify:factor-out-column-def

Conversation

@hkdsun
Copy link
Contributor

@hkdsun hkdsun commented Mar 8, 2023

Motivation / Background

This Pull Request has been created because our team at Shopify is implementing a custom ActiveRecord adapter to integrate with Vitess, and we would like to overload the valid_{column,table}_definition_options methods and add additional valid options for schema migrations. For example:

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

Detail

This Pull Request, as the simplest possible change, factors out the various valid_{table,column,primary_key}_definition_options to be a public method on an adapter instance.

This allows subclassing adapters to cleanly override their ancestor class' valid options.

Additional information

I don't see any harm in this, maybe except the awkwardness of the roundabout reference of

TableDefinition#valid_column_definition_options -> SchemaStatements#valid_column_definition_options -> ColumnDefinition::OPTION_NAMES

Checklist

Before submitting the PR make sure the following are checked:

  • This Pull Request is related to one change. Changes that are unrelated should be opened in separate PRs.
  • Commit message has a detailed description of what changed and why. If this PR fixes a related issue include it in the commit message. Ex: [Fix #issue-number]
  • Tests are added or updated if you fix a bug or add a feature.
  • CHANGELOG files are updated for the changed libraries if there is a behavior change or additional feature. Minor bug fixes and documentation changes should not be included.

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.
@hkdsun hkdsun force-pushed the factor-out-column-def branch from 44b452f to cdb8957 Compare March 8, 2023 21:40
@eileencodes eileencodes merged commit bde7821 into rails:main Mar 9, 2023
@eileencodes eileencodes deleted the factor-out-column-def branch March 9, 2023 16:17
@matthewd
Copy link
Member

matthewd commented Mar 9, 2023

I'm not sure these should be public, but if they are, they should almost certainly be nodoc.

davinlagerroos pushed a commit to umn-asr/oracle-enhanced that referenced this pull request Feb 21, 2024
See rails/rails#46178
and rails/rails#47609

These were the options that were failing in the test suite.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants