lib/apartment/adapters/mysql2_adapter.rb in apartment-0.24.3 vs lib/apartment/adapters/mysql2_adapter.rb in apartment-0.25.0

- old
+ new

@@ -1,9 +1,9 @@ require 'apartment/adapters/abstract_adapter' module Apartment - module Database + module Tenant def self.mysql2_adapter(config) Apartment.use_schemas ? Adapters::Mysql2SchemaAdapter.new(config) : Adapters::Mysql2Adapter.new(config) @@ -22,11 +22,11 @@ # @param {String} tenant Tenant name # def connect_to_new(tenant = nil) super rescue Mysql2::Error - Apartment::Database.reset + Apartment::Tenant.reset raise DatabaseNotFound, "Cannot find tenant #{environmentify(tenant)}" end end class Mysql2SchemaAdapter < AbstractAdapter @@ -59,19 +59,15 @@ return reset if tenant.nil? Apartment.connection.execute "use #{environmentify(tenant)}" rescue ActiveRecord::StatementInvalid - Apartment::Database.reset + Apartment::Tenant.reset raise DatabaseNotFound, "Cannot find tenant #{environmentify(tenant)}" end def process_excluded_model(model) model.constantize.tap do |klass| - # some models (such as delayed_job) seem to load and cache their column names before this, - # so would never get the default prefix, so reset first - klass.reset_column_information - # 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