Refactor/Fix missing foreign key index detection + missing FK constraints heuristics and update tests#34
Conversation
* Simplify the logic for detecting missing foreign key indexes by directly using foreign key information. * Update tests to reflect changes in foreign key and index detection, including new expected results for users and posts tables. * Modify the database schema in tests to include new foreign key relationships and columns for accurate testing.
…c and update tests * Refactor the logic to identify missing foreign key constraints by considering existing constraints and polymorphic associations. * Add tests to ensure columns with existing foreign key constraints and polymorphic associations are correctly excluded from results. * Update the test database schema to include new tables for comprehensive testing.
|
I'm going to push later the ignore list feature as well and if I got time/succeed, I will have to improve the DetectFkColumn algorithm. i suspect we can better improve the |
7ef210f to
6ed6baa
Compare
…ive tests * Refactor the `call` method to improve detection of foreign key columns, accommodating underscored prefixes and mixed-case names. * Update the `pluralize` method to normalize table names before applying pluralization rules. * Add new test cases to validate detection for various scenarios, including uncountable nouns and irregular plurals.
|
@pawurb I found the root cause for the main isuse was this line: I've tested the fix on my production app, and with it I was able to detect 5 real missing FK constraints! |
|
@pawurb I believe I'm done with the improvements and fixes, I don't have anything else for now. You can review / cut a release whenever you can! |
|
@chaadow thanks a lot! I'll proceed with releasing this and related rails-pg-extras changes |
Missing FK indices Algorithm
==> I went from 67 missing foreign keys ( with false positives ) to over 200 in my production application 💀. I checked manually and indeed, it turns out I have a LOT of missing indices. Which for me indicates that the
DetectFkColumnwas a bit weird ... EDIT: indeed the root cause was that cases such asuser_account_idwere returninguserinstead ofuser_account!missing Fk constraints check heuristics algorithm
Enhance missing foreign key detection (
missing_fk_constraints) logic and update testspolymorphic associationsAdd ignore list to missing_fk_constraint check
IgnoreListclass which can be later be used in other checks if needed. As input it takes an ignore list, then can determine if a column in a table is ignored based on the ignore list.Enhance and Fix foreign key column detection logic
FkDetectColumnclass to improve detection of foreign key columns, accommodating underscored prefixes and mixed-case names, such asuser_account_idrelated to pawurb/rails-pg-extras#58