bensheldon / good_job

Multithreaded, Postgres-based, Active Job backend for Ruby on Rails.
https://goodjob-demo.herokuapp.com/
MIT License
2.65k stars 195 forks source link

PG::UndefinedColumn: ERROR: column good_job_processes.lock_type does not exist #1405

Closed mhenrixon closed 2 months ago

mhenrixon commented 2 months ago

Started having these errors in my logs:

job    |   TRANSACTION (0.3ms)  COMMIT
job    |    (0.4ms)  /*application:Intracar*/ SET application_name = 'GoodJob::Notifier'
job    |    (0.1ms)  /*application:Intracar*/ LISTEN good_job
job    | Notifier subscribed with LISTEN
job    |   GoodJob::Process Load (4.4ms)  /*application:Intracar*/ SELECT "good_job_processes".* FROM "good_job_processes" LEFT JOIN pg_locks ON pg_locks.locktype = 'advisory' AND pg_locks.objsubid = 1 AND pg_locks.classid = ('x' || substr(md5('good_job_processes' || '-' || "good_job_processes"."id"::text), 1, 16))::bit(32)::int AND pg_locks.objid = (('x' || substr(md5('good_job_processes' || '-' || "good_job_processes"."id"::text), 1, 16))::bit(64) << 32)::bit(32)::int WHERE ("good_job_processes"."lock_type" = $1 AND "pg_locks"."locktype" IS NULL OR "good_job_processes"."lock_type" IS NULL AND "good_job_processes"."updated_at" < '2024-07-08 13:50:09.650029') ORDER BY "good_job_processes"."id" ASC LIMIT $2  [["lock_type", 1], ["LIMIT", 1000]]
job    |    (0.2ms)  /*application:Intracar*/ UNLISTEN *
job    | Notifier unsubscribed with UNLISTEN
job    | Notifier errored: ActiveRecord::StatementInvalid: PG::UndefinedColumn: ERROR:  column good_job_processes.lock_type does not exist
job    | LINE 1: ...xt), 1, 16))::bit(64) << 32)::bit(32)::int WHERE ("good_job_...

I can't make sense of it or find any information to suggest what is wrong. Any whelp appreciated.

bensheldon commented 2 months ago

The migration was introduced in v3.29.0 (#999).

If you recently upgraded to GoodJob v4, you'll need to go to version 3.99 and run bundle exec rails g good_job:update and apply and deploy those migrations, then upgrade to v4.

https://github.com/bensheldon/good_job#upgrading-v3-to-v4

mhenrixon commented 2 months ago

Oh, that explains things! I didn't see that I bumped a major version! Thank you for the quick reply.

jake commented 2 months ago

im getting this error on 4.0.0, but nothing meaningful happens when I run the update command.

11:10 ~/Sites/backend [dependabot/bundler/good_job-4.0.0] $ bundle exec rails g good_job:update
        skip  db/migrate/20240709151103_create_good_jobs.rb

ran bundle install and restarted everything. I get this error when I visit the processes tab of the admin:

Showing /Users/jacob/.asdf/installs/ruby/3.3.2/lib/ruby/gems/3.3.0/gems/good_job-4.0.0/app/views/good_job/processes/index.html.erb where line #21 raised:

PG::UndefinedColumn: ERROR:  column good_job_processes.lock_type does not exist
LINE 1: ...xt), 1, 16))::bit(64) << 32)::bit(32)::int WHERE ("good_job_...
                                                             ^
Rails.root: /Users/jacob/Sites/backend

and a similar one on performance:

Showing /Users/jacob/.asdf/installs/ruby/3.3.2/lib/ruby/gems/3.3.0/gems/good_job-4.0.0/app/views/good_job/performances/show.html.erb where line #18 raised:

PG::UndefinedColumn: ERROR:  column "duration" does not exist
LINE 4:                             AVG(duration) AS avg_duration,
                                        ^
Rails.root: /Users/jacob/Sites/backend

here are all the good_job related migrations I have:

Screenshot 2024-07-09 at 11 14 28 AM
bensheldon commented 2 months ago

It looks like you didn't generate and run all of the migrations on v3.99.

(I squash all of the migrations every new release. That's so that someone adopting GoodJob for the first time doesn't have to generate like 40 migration files all at once.)

You should point your gemfile to 3.99, then run bin/rails g good_job:update to get the migrations.

jake commented 2 months ago

yup, that was it! I wonder if you could somehow detect that? or squash them one version later perhaps. I see now the docs do list it in that order, but totally missed that.

11:30 ~/Sites/backend [main] $ bundle exec rails g good_job:update
        skip  db/migrate/20240709155228_create_good_jobs.rb
   identical  db/migrate/20240117153100_create_good_job_settings.rb
   identical  db/migrate/20240117153101_create_index_good_jobs_jobs_on_priority_created_at_when_unfinished.rb
   identical  db/migrate/20240117153102_create_good_job_batches.rb
   identical  db/migrate/20240117153103_create_good_job_executions.rb
   identical  db/migrate/20240117153104_create_good_jobs_error_event.rb
   identical  db/migrate/20240117153105_recreate_good_job_cron_indexes_with_conditional.rb
   identical  db/migrate/20240117153106_create_good_job_labels.rb
   identical  db/migrate/20240117153107_create_good_job_labels_index.rb
   identical  db/migrate/20240117153108_remove_good_job_active_id_index.rb
   identical  db/migrate/20240520135504_create_index_good_job_jobs_for_candidate_lookup.rb
   identical  db/migrate/20240520135505_create_good_job_execution_error_backtrace.rb
      create  db/migrate/20240709155229_create_good_job_process_lock_ids.rb
      create  db/migrate/20240709155230_create_good_job_process_lock_indexes.rb
      create  db/migrate/20240709155723_create_good_job_execution_duration.rb

thanks!