djezzzl / database_consistency

The tool to avoid various issues due to inconsistencies and inefficiencies between a database schema and application models.
MIT License
1.02k stars 43 forks source link

Excluding Database Connections to Non Primary Databases Including sqlserver #182

Closed epidevops closed 1 year ago

epidevops commented 1 year ago

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:

djezzzl commented 1 year ago

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.

djezzzl commented 1 year ago

Hi @epidevops,

Just merged: https://github.com/djezzzl/database_consistency/pull/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!