Excluding Database Connections to Non Primary Databases Including sqlserver
Closed this issue · 2 comments
Hello, I have implemented your gem and it has proved quite useful. Is the feature request below valid or is there a configuration that can allow me to disable specific database connections?
Issue
In environment with multiple database connections including one to a sqlserver database database_consistency cannot run because non primary databases cannot be excluded.
Feature
Ability to configure gem to exclude specified database connections.
Connection database.yml setup
default: &default
adapter: postgresql
encoding: unicode
etc: ....
database2: &database2
adapter: postgresql
encoding: unicode
etc: ....
database_tasks: false
database3: &database3
adapter: sqlserver
etc: ....
database_tasks: false
development:
primary:
<<: *default
database2:
<<: *database2
database3:
<<: *database3
test:
primary:
<<: *default
database2:
<<: *database2
database3:
<<: *database3
Config .database_consistency.yml setup
DatabaseConsistencySettings:
color: true
log_level: DEBUG
Database_2_table_1:
enabled: false
Database_2_table_2:
enabled: false
Database_2_table_3:
enabled: false
Database_3_table_1:
enabled: false
Error log generated when running either of the commands below:
- bundle exec database_consistency
- bundle exec database_consistency -c .database_consistency.yml
<===begin===>
.rvm/gems/ruby-3.2.0/gems/tiny_tds-2.1.5/lib/tiny_tds/client.rb:60:in `connect': �[1mServer name not found in configuration files (�[1;4mTinyTds::Error�[m�[1m)�[m
from .rvm/gems/ruby-3.2.0/gems/tiny_tds-2.1.5/lib/tiny_tds/client.rb:60:in `initialize'
from .rvm/gems/ruby-3.2.0/gems/activerecord-sqlserver-adapter-7.0.0.0/lib/active_record/connection_adapters/sqlserver_adapter.rb:73:in `new'
from .rvm/gems/ruby-3.2.0/gems/activerecord-sqlserver-adapter-7.0.0.0/lib/active_record/connection_adapters/sqlserver_adapter.rb:73:in `dblib_connect'
from .rvm/gems/ruby-3.2.0/gems/activerecord-sqlserver-adapter-7.0.0.0/lib/active_record/connection_adapters/sqlserver_adapter.rb:66:in `new_client'
from .rvm/gems/ruby-3.2.0/gems/activerecord-sqlserver-adapter-7.0.0.0/lib/active_record/sqlserver_base.rb:11:in `sqlserver_connection'
from .rvm/gems/ruby-3.2.0/gems/activerecord-7.0.4.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:656:in `public_send'
from .rvm/gems/ruby-3.2.0/gems/activerecord-7.0.4.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:656:in `new_connection'
from .rvm/gems/ruby-3.2.0/gems/activerecord-7.0.4.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:700:in `checkout_new_connection'
from .rvm/gems/ruby-3.2.0/gems/activerecord-7.0.4.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:679:in `try_to_checkout_new_connection'
from .rvm/gems/ruby-3.2.0/gems/activerecord-7.0.4.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:640:in `acquire_connection'
from .rvm/gems/ruby-3.2.0/gems/activerecord-7.0.4.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:341:in `checkout'
from .rvm/gems/ruby-3.2.0/gems/activerecord-7.0.4.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:181:in `connection'
from .rvm/gems/ruby-3.2.0/gems/activerecord-7.0.4.2/lib/active_record/connection_adapters/abstract/connection_handler.rb:211:in `retrieve_connection'
from .rvm/gems/ruby-3.2.0/gems/activerecord-7.0.4.2/lib/active_record/connection_handling.rb:313:in `retrieve_connection'
from .rvm/gems/ruby-3.2.0/gems/activerecord-7.0.4.2/lib/active_record/connection_handling.rb:280:in `connection'
from .rvm/gems/ruby-3.2.0/gems/database_consistency-1.7.4/lib/database_consistency/helper.rb:31:in `block in models'
from .rvm/gems/ruby-3.2.0/gems/database_consistency-1.7.4/lib/database_consistency/helper.rb:30:in `select'
from .rvm/gems/ruby-3.2.0/gems/database_consistency-1.7.4/lib/database_consistency/helper.rb:30:in `models'
from .rvm/gems/ruby-3.2.0/gems/database_consistency-1.7.4/lib/database_consistency/helper.rb:39:in `parent_models'
from .rvm/gems/ruby-3.2.0/gems/database_consistency-1.7.4/lib/database_consistency/processors/columns_processor.rb:17:in `check'
from .rvm/gems/ruby-3.2.0/gems/database_consistency-1.7.4/lib/database_consistency/processors/base_processor.rb:30:in `reports'
from .rvm/gems/ruby-3.2.0/gems/database_consistency-1.7.4/lib/database_consistency/processors/base_processor.rb:15:in `block in reports'
from .rvm/gems/ruby-3.2.0/gems/database_consistency-1.7.4/lib/database_consistency/processors/base_processor.rb:14:in `each'
from .rvm/gems/ruby-3.2.0/gems/database_consistency-1.7.4/lib/database_consistency/processors/base_processor.rb:14:in `flat_map'
from .rvm/gems/ruby-3.2.0/gems/database_consistency-1.7.4/lib/database_consistency/processors/base_processor.rb:14:in `reports'
from .rvm/gems/ruby-3.2.0/gems/database_consistency-1.7.4/lib/database_consistency.rb:100:in `run'
from .rvm/gems/ruby-3.2.0/gems/database_consistency-1.7.4/bin/database_consistency:78:in `<top (required)>'
from .rvm/gems/ruby-3.2.0/bin/database_consistency:25:in `load'
from .rvm/gems/ruby-3.2.0/bin/database_consistency:25:in `<main>'
from .rvm/gems/ruby-3.2.0/bin/ruby_executable_hooks:22:in `eval'
from .rvm/gems/ruby-3.2.0/bin/ruby_executable_hooks:22:in `<main>'
<===end===>
Hi @epidevops,
Thank you for using the gem! And I'm sorry it took me long to answer.
As I understand your problem, you have multiple databases. Some of the ActiveRecord models are mapped to the tables in those databases.
For some reason (I didn't quite get why), you can't connect to those databases when you run database_consistency
.
So you would like to exclude those models/databases from being checked.
Your feature, which proposes exclusion by database, sounds excellent to me.
For now, please try to define a list of models that have tables in those databases. It may help you as a temporary workaround. Please, let me know if it worked out.
Hi @epidevops,
Just merged: #204.
I'm sorry it took me long to implement this.
It was released on 1.7.12.
You can turn it off by following this documentation: https://github.com/djezzzl/database_consistency/wiki/disable-per-database-connection
I hope it helps! Have a great time!