-
Notifications
You must be signed in to change notification settings - Fork 361
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove foreign key contraint in table job_warnings on 'fk_jobs_id' (#…
…4174) 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.
- Loading branch information
Showing
2 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
db/migrations/20250116144231_remove_unnecessary_fk_in_job_warnings.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Sequel.migration do | ||
up do | ||
unless foreign_key_list(:job_warnings).empty? | ||
alter_table :job_warnings do | ||
drop_foreign_key :fk_jobs_id | ||
end | ||
end | ||
end | ||
end |
31 changes: 31 additions & 0 deletions
31
spec/migrations/20250116144231_remove_unnecessary_fk_in_job_warnings_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
require 'spec_helper' | ||
require 'migrations/helpers/migration_shared_context' | ||
|
||
RSpec.describe "migration to remove foreign key constraint on table 'job_warnings' and column 'fk_jobs_id'", isolation: :truncation, type: :migration do | ||
include_context 'migration' do | ||
let(:migration_filename) { '20250116144231_remove_unnecessary_fk_in_job_warnings.rb' } | ||
end | ||
|
||
describe 'job_warnings table' do | ||
it 'removes the fk constraint as well as the column' do | ||
Sequel::Migrator.run(db, migrations_path, target: current_migration_index, allow_missing_migration_files: true) | ||
|
||
expect(db.foreign_key_list(:job_warnings)).to be_empty | ||
expect(db[:job_warnings].columns).not_to include(:fk_jobs_id) | ||
end | ||
|
||
context 'foreign key constraint does not exist' do | ||
before do | ||
unless db.foreign_key_list(:job_warnings).empty? | ||
db.alter_table(:job_warnings) do | ||
drop_foreign_key :fk_jobs_id | ||
end | ||
end | ||
end | ||
|
||
it 'does not fail' do | ||
expect { Sequel::Migrator.run(db, migrations_path, target: current_migration_index, allow_missing_migration_files: true) }.not_to raise_error | ||
end | ||
end | ||
end | ||
end |