Skip to content

Commit 2cf1a79

Browse files
committed
Remove foreign key contraint in table job_warnings on 'fk_jobs_id'
The job_warnings table was created in a wrong way. There are two columns 'job_id' and 'fk_jobs_id'. There is a foreign key constraint on 'fk_jobs_id', which references jobs(id). CC coding never inserts data into 'fk_jobs_id', but only into 'job_id'. So the foreign key constraint is not needed and causes way slower cleanup of pollable jobs, which can even run into DB statement timeouts and cause an ever growing table.
1 parent 1dac91f commit 2cf1a79

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Sequel.migration do
2+
up do
3+
alter_table :job_warnings do
4+
drop_foreign_key :fk_jobs_id
5+
end
6+
end
7+
end
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
require 'spec_helper'
2+
require 'migrations/helpers/migration_shared_context'
3+
4+
RSpec.describe "migration to remove foreign key constraint on table 'job_warnings' and column 'fk_jobs_id'", isolation: :truncation, type: :migration do
5+
include_context 'migration' do
6+
let(:migration_filename) { '20250116144231_remove_unnecessary_fk_in_job_warnings.rb' }
7+
end
8+
9+
describe 'job_warnings table' do
10+
it 'removed the fk constraint as well as the column' do
11+
Sequel::Migrator.run(db, migrations_path, target: current_migration_index, allow_missing_migration_files: true)
12+
13+
expect(db.foreign_key_list(:job_warnings)).to be_empty
14+
expect(db[:job_warnings].columns).not_to include(:fk_jobs_id)
15+
end
16+
end
17+
end

0 commit comments

Comments
 (0)