lib/apartment/adapters/mysql2_adapter.rb in apartment-1.0.2 vs lib/apartment/adapters/mysql2_adapter.rb in apartment-1.1.0

- old
+ new

@@ -19,21 +19,12 @@ @default_tenant = config[:database] end protected - # Connect to new tenant - # Abstract adapter will catch generic ActiveRecord error - # Catch specific adapter errors here - # - # @param {String} tenant Tenant name - # - def connect_to_new(tenant = nil) - super - rescue Mysql2::Error - Apartment::Tenant.reset - raise TenantNotFound, "Cannot find tenant #{environmentify(tenant)}" + def rescue_from + Mysql2::Error end end class Mysql2SchemaAdapter < AbstractAdapter def initialize(config) @@ -47,36 +38,34 @@ # def reset Apartment.connection.execute "use `#{default_tenant}`" end - # Set the table_name to always use the default tenant for excluded models - # - def process_excluded_models - Apartment.excluded_models.each{ |model| process_excluded_model(model) } - end - protected # Connect to new tenant # def connect_to_new(tenant) return reset if tenant.nil? Apartment.connection.execute "use `#{environmentify(tenant)}`" - rescue ActiveRecord::StatementInvalid + rescue ActiveRecord::StatementInvalid => exception Apartment::Tenant.reset - raise TenantNotFound, "Cannot find tenant #{environmentify(tenant)}" + raise_connect_error!(tenant, exception) end def process_excluded_model(model) model.constantize.tap do |klass| # Ensure that if a schema *was* set, we override table_name = klass.table_name.split('.', 2).last klass.table_name = "#{default_tenant}.#{table_name}" end + end + + def reset_on_connection_exception? + true end end end end