Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does the gem support multiple databases? #126

Closed
greytape opened this issue Aug 19, 2022 · 4 comments
Closed

Does the gem support multiple databases? #126

greytape opened this issue Aug 19, 2022 · 4 comments

Comments

@greytape
Copy link

greytape commented Aug 19, 2022

Hi,

Gem looks great, and I'd love to try it out, but I'm getting the error below. This suggests that the gem is having trouble with more than one database in database.yml, as it is looking for a table on the primary database that is only available on the secondary database. Is this expected behaviour, as multiple databases are not supported?

(In log extract below I have changed the names of the actual primary database to primary_database and the actual table to table_on_secondary_database for clarity)

/usr/local/bundle/gems/mysql2-0.5.3/lib/mysql2/client.rb:131:in `_query': Mysql2::Error: Table 'primary_database.table_on_secondary_database' doesn't exist (ActiveRecord::StatementInvalid)
        from /usr/local/bundle/gems/mysql2-0.5.3/lib/mysql2/client.rb:131:in `block in query'
        from /usr/local/bundle/gems/mysql2-0.5.3/lib/mysql2/client.rb:130:in `handle_interrupt'
        from /usr/local/bundle/gems/mysql2-0.5.3/lib/mysql2/client.rb:130:in `query'
        from /usr/local/bundle/gems/rack-mini-profiler-2.3.3/lib/patches/db/mysql2/alias_method.rb:22:in `query'
        from /usr/local/bundle/gems/activerecord-6.1.6.1/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:206:in `block (2 levels) in execute'
        from /usr/local/bundle/gems/activesupport-6.1.6.1/lib/active_support/dependencies/interlock.rb:48:in `block in permit_concurrent_loads'
        from /usr/local/bundle/gems/activesupport-6.1.6.1/lib/active_support/concurrency/share_lock.rb:187:in `yield_shares'
        from /usr/local/bundle/gems/activesupport-6.1.6.1/lib/active_support/dependencies/interlock.rb:47:in `permit_concurrent_loads'
        from /usr/local/bundle/gems/activerecord-6.1.6.1/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:205:in `block in execute'
        from /usr/local/bundle/gems/activerecord-6.1.6.1/lib/active_record/connection_adapters/abstract_adapter.rb:696:in `block (2 levels) in log'
        from /usr/local/bundle/gems/activesupport-6.1.6.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:26:in `block (2 levels) in synchronize'
        from /usr/local/bundle/gems/activesupport-6.1.6.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `handle_interrupt'
        from /usr/local/bundle/gems/activesupport-6.1.6.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `block in synchronize'
        from /usr/local/bundle/gems/activesupport-6.1.6.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `handle_interrupt'
        from /usr/local/bundle/gems/activesupport-6.1.6.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `synchronize'
        from /usr/local/bundle/gems/activerecord-6.1.6.1/lib/active_record/connection_adapters/abstract_adapter.rb:695:in `block in log'
        from /usr/local/bundle/gems/activesupport-6.1.6.1/lib/active_support/notifications/instrumenter.rb:24:in `instrument'
        from /usr/local/bundle/gems/activerecord-6.1.6.1/lib/active_record/connection_adapters/abstract_adapter.rb:687:in `log'
        from /usr/local/bundle/gems/activerecord-6.1.6.1/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:204:in `execute'
        from /usr/local/bundle/gems/activerecord-6.1.6.1/lib/active_record/connection_adapters/mysql/database_statements.rb:52:in `execute'
        from /usr/local/bundle/gems/marginalia-1.11.1/lib/marginalia.rb:71:in `execute_with_marginalia'
        from /usr/local/bundle/gems/activerecord-6.1.6.1/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:215:in `execute_and_free'
        from /usr/local/bundle/gems/activerecord-6.1.6.1/lib/active_record/connection_adapters/mysql/schema_statements.rb:11:in `indexes'
        from /usr/local/bundle/gems/database_consistency-1.1.15/lib/database_consistency/processors/indexes_processor.rb:19:in `block in check'
        from /usr/local/bundle/gems/database_consistency-1.1.15/lib/database_consistency/processors/indexes_processor.rb:16:in `each'
        from /usr/local/bundle/gems/database_consistency-1.1.15/lib/database_consistency/processors/indexes_processor.rb:16:in `flat_map'
        from /usr/local/bundle/gems/database_consistency-1.1.15/lib/database_consistency/processors/indexes_processor.rb:16:in `check'
        from /usr/local/bundle/gems/database_consistency-1.1.15/lib/database_consistency/processors/base_processor.rb:29:in `reports'
        from /usr/local/bundle/gems/database_consistency-1.1.15/lib/database_consistency/processors/base_processor.rb:14:in `block in reports'
        from /usr/local/bundle/gems/database_consistency-1.1.15/lib/database_consistency/processors/base_processor.rb:13:in `each'
        from /usr/local/bundle/gems/database_consistency-1.1.15/lib/database_consistency/processors/base_processor.rb:13:in `flat_map'
        from /usr/local/bundle/gems/database_consistency-1.1.15/lib/database_consistency/processors/base_processor.rb:13:in `reports'
        from /usr/local/bundle/gems/database_consistency-1.1.15/lib/database_consistency.rb:53:in `run'
        from /usr/local/bundle/gems/database_consistency-1.1.15/bin/database_consistency:69:in `<top (required)>'
        from /usr/local/bundle/bin/database_consistency:25:in `load'
        from /usr/local/bundle/bin/database_consistency:25:in `<top (required)>'
        from /usr/local/bundle/gems/bundler-2.3.14/lib/bundler/cli/exec.rb:58:in `load'
        from /usr/local/bundle/gems/bundler-2.3.14/lib/bundler/cli/exec.rb:58:in `kernel_load'
        from /usr/local/bundle/gems/bundler-2.3.14/lib/bundler/cli/exec.rb:23:in `run'
        from /usr/local/bundle/gems/bundler-2.3.14/lib/bundler/cli.rb:483:in `exec'
        from /usr/local/bundle/gems/bundler-2.3.14/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
        from /usr/local/bundle/gems/bundler-2.3.14/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
        from /usr/local/bundle/gems/bundler-2.3.14/lib/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
        from /usr/local/bundle/gems/bundler-2.3.14/lib/bundler/cli.rb:31:in `dispatch'
        from /usr/local/bundle/gems/bundler-2.3.14/lib/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
        from /usr/local/bundle/gems/bundler-2.3.14/lib/bundler/cli.rb:25:in `start'
        from /usr/local/bundle/gems/bundler-2.3.14/exe/bundle:48:in `block in <top (required)>'
        from /usr/local/bundle/gems/bundler-2.3.14/lib/bundler/friendly_errors.rb:103:in `with_friendly_errors'
        from /usr/local/bundle/gems/bundler-2.3.14/exe/bundle:36:in `<top (required)>'
        from /api/bin/bundle:113:in `load'
        from /api/bin/bundle:113:in `<main>'

In the model that is throwing the error, we have the database defined as follows (names changed for clarity):

  class SecondaryDatabaseRecord < SecondaryDatabaseApplicationRecord
    self.table_name = "table_on_secondary_database"

Thanks!

@djezzzl
Copy link
Owner

djezzzl commented Aug 20, 2022

Hello @greytape ,

Thank you for letting me know about this issue! I'll do my best to have a look as soon as possible and fix this!

Or maybe you would like to investigate and contribute with the fix?

@greytape
Copy link
Author

@djezzzl - many thanks for the quick response. I'll leave the investigation to you if that's ok, afraid I wouldn't know where to start!

@djezzzl
Copy link
Owner

djezzzl commented Sep 10, 2022

Hi @greytape,

I'm sorry it took me so long to fix the issue.
The issue was fixed within: #129.

Could you please try new released version 1.2.2 and confirm if everything is okay for you?
I would be happy if you share in case anything is wrong or you have some ideas.

Have a great day!

@djezzzl djezzzl closed this as completed Sep 10, 2022
@greytape
Copy link
Author

Amazing, thanks for the quick response. Have checked v.1.2.2 and the command now works fine with our codebase! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants