rails / solid_queue

Database-backed Active Job backend
MIT License
1.95k stars 130 forks source link

`ActiveRecord::MismatchedForeignKey` in new migration file #326

Closed tmimura39 closed 2 months ago

tmimura39 commented 2 months ago

Running db:prepare (or db:schema:load:queue) based on a single migration file from this commit will result in the following error

ActiveRecord::MismatchedForeignKey: Column `job_id` on table `solid_queue_blocked_executions` does not match column `id` on `solid_queue_jobs`, which has type `bigint`. To resolve this issue, change the type of the `job_id` column on `solid_queue_blocked_executions` to be :bigint. (For example `t.bigint :job_id`). (ActiveRecord::MismatchedForeignKey)
Original message: Trilogy::ProtocolError: 3780: Referencing column 'job_id' and referenced column 'id' in foreign key constraint 'fk_rails_4cd34e2228' are incompatible.

Since rails nowadays creates the primary key (id) as a bigint, shouldn't the job_id in the executions table also be a bigint? https://github.com/rails/solid_queue/blob/d2732610056ae265616d4f73934bfa41849dfc33/lib/generators/solid_queue/install/templates/db/queue_schema.rb#L3

If there is a reason why jobs.id should be an integer instead of a bigint, I think it should be explicitly stated.

rosa commented 2 months ago

Huh, no! That's totally a mistake. It should be a bigint. I'm quite surprised how that ended up as an integer if the original way that table was created was via this migration. That should have been automatically a bigint 😕

rosa commented 2 months ago

All the job_id references in the _executions tables were wrong too! I'm stumped about why this was the case 😕 I've fixed it now and shipped version 0.8.2 with the change.

rosa commented 2 months ago

I think this should be fixed now, but let me know if that's not the case for you, and I'll reopen!