active_record_doctor icon indicating copy to clipboard operation
active_record_doctor copied to clipboard

Suggestion: Allow (or require) foreign keys to use BigInt even if the primary uses Integer

Open hlascelles opened this issue 7 months ago • 3 comments

Many of us have older codebases with primary keys as integers, not bigint. ARD allows these exceptions until you get round to migrating them.

What we don't want is to allow the problem to propagate. I definitely don't want FKIDs to be integer when the primary is bigint, but I want to allow (force?) all new FKIDs to be be bigint regardless of the PKID type. This will the future big fix migration to concentrate on the primary tables only.

I am prepared to ignore for the (rare?, nearly impossible?) possibility of a very large number being put in the FKID column. That Shouldn't Happen.

Would you like a check for this, with the standard exceptions system for existing tables?

hlascelles avatar May 12 '25 10:05 hlascelles

I think having a config option named like ignore_columns_with_larger_type for mismatched_foreign_key_type checker would be good.

Yes, it is really a problem when foreign key has a shorter type than a related primary key, but when it has a longer type - this is not much of a problem.

fatkodima avatar May 12 '25 10:05 fatkodima

OK, will give it a go with a PR 👍 !

hlascelles avatar May 19 '25 07:05 hlascelles

Thanks for reporting the problem, @hlascelles! I really like your idea! I think you can proceed with the PR.

gregnavis avatar May 19 '25 08:05 gregnavis