lib/active_replicas/railtie.rb in active_replicas-0.2.0 vs lib/active_replicas/railtie.rb in active_replicas-0.2.1
- old
+ new
@@ -1,24 +1,36 @@
+require 'active_support/core_ext/class/attribute_accessors'
+
module ActiveReplicas
class Railtie < Rails::Railtie
cattr_reader :connection_handler
cattr_accessor :replica_delegated_methods
cattr_accessor :primary_delegated_methods
+ # Reports what the database can handle, see URL for more information:
+ # https://github.com/rails/rails/blob/master/activerecord/lib/active_record/connection_adapters/abstract/database_limits.rb
+ DATABASE_LIMITS_METHODS = [
+ :allowed_index_name_length, :column_name_length,
+ :columns_per_multicolumn_index, :columns_per_table, :in_clause_length,
+ :index_name_length, :indexes_per_table, :joins_per_query,
+ :sql_query_length, :table_alias_length, :table_name_length
+ ]
+
# All the methods which are safe to be delegated to a replica.
@@replica_delegated_methods = (
+ DATABASE_LIMITS_METHODS +
[
:active?, :cacheable_query, :case_sensitive_comparison,
:case_sensitive_modifier, :case_insensitive_comparison,
:clear_query_cache, :column_name_for_operation, :columns,
:disable_query_cache!, :disconnect!, :enable_query_cache!,
:exec_query, :prepared_statements, :query_cache_enabled, :quote,
:quote_column_name, :quote_table_name,
:quote_table_name_for_assignment, :raw_connection, :reconnect!,
:sanitize_limit, :schema_cache, :select, :select_all, :select_one,
:select_rows, :select_value, :select_values, :substitute_at, :to_sql,
- :type_cast, :valid_type?, :verify!
+ :type_cast, :uncached, :valid_type?, :verify!
]
).uniq
# Rails methods that translate to SQL DDL (data definition language).
DDL_METHODS = [