From 3ab4ab5d1bd3d0a63b354c0cd6127a715d4f9996 Mon Sep 17 00:00:00 2001 From: Tony Novak Date: Wed, 28 Jul 2021 16:13:56 -0400 Subject: [PATCH] Fix conflicting annotations for multiple-database scenario Given a Rails application with multiple databases, tables in two databases with the same table name, and corresponding models with different names, some files get annotated with the wrong table's schema. The issue is that some of the patterns include `%TABLE_NAME%`, which will be identical between the two tables, even though they have different model names. This fixes the issue by eliminating the use of the table name when the model is not connected to the primary database. Fixes #891. --- lib/annotate/annotate_models.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/annotate/annotate_models.rb b/lib/annotate/annotate_models.rb index dc2901a3..76a6a697 100644 --- a/lib/annotate/annotate_models.rb +++ b/lib/annotate/annotate_models.rb @@ -538,7 +538,7 @@ def annotate(klass, file, header, options = {}) klass.reset_column_information info = get_schema_info(klass, header, options) model_name = klass.name.underscore - table_name = klass.table_name + table_name = klass.table_name if klass.connection_specification_name == ActiveRecord::Base.name model_file_name = File.join(file) annotated = [] @@ -760,7 +760,7 @@ def remove_annotations(options = {}) klass = get_model_class(file) if klass < ActiveRecord::Base && !klass.abstract_class? model_name = klass.name.underscore - table_name = klass.table_name + table_name = klass.table_name if klass.connection_specification_name == ActiveRecord::Base.name model_file_name = file deannotated_klass = true if remove_annotation_of_file(model_file_name, options)