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.
I've just rebased this branch to develop. Note that this branch previously had an integration test for the new behavior, but since the integration tests were removed in #959, these tests are no longer included.
If integration tests are reintroduced upstream, they're in this commit: 385c293a0dbc2f822b77817de79c527c68b30d19.
@afn sorry to hijack the thread a bit, but if you're interested I could get this added to my fork https://github.com/drwl/annotaterb. Since I'm still on the list of maintainers for this gem I get pinged about activity by Github every now and then.
I would just need instructions on setting up a proof of concept Rails app with the case you're talking about (multiple databases + models with same table name).
Thanks @drwl!
I've pushed an example app to https://github.com/cygnuseducation/annotate-test-app. This test case doesn't actually end up incorrectly annotating the files, but it does incorrectly detect that there are relevant changes to the annotations:
➜ test-app git:(main) annotaterb models
Annotating models
Annotated (2): test/factories/users.rb, test/factories/users.rb
See also the integration test in 385c293a0dbc2f822b77817de79c527c68b30d19.
Thanks!
@afn would you mind if we continued discussions in https://github.com/drwl/annotaterb/pull/135?