forked from cloudfoundry/cloud_controller_ng
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request cloudfoundry#3703 from sap-contributions/add-dynam…
…ic-job-prios Add dynamic job priorities
- Loading branch information
Showing
12 changed files
with
306 additions
and
5 deletions.
There are no files selected for viewing
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
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
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
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
39 changes: 39 additions & 0 deletions
39
db/migrations/20240314131908_add_user_guid_to_jobs_table.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,39 @@ | ||
Sequel.migration do | ||
# adding an index concurrently cannot be done within a transaction | ||
no_transaction | ||
|
||
up do | ||
if database_type == :postgres | ||
alter_table :jobs do | ||
add_column :user_guid, String, size: 255, if_not_exists: true | ||
add_index :user_guid, name: :jobs_user_guid_index, if_not_exists: true, concurrently: true | ||
end | ||
|
||
elsif database_type == :mysql | ||
alter_table :jobs do | ||
add_column :user_guid, String, size: 255 unless @db.schema(:jobs).map(&:first).include?(:user_guid) | ||
# rubocop:disable Sequel/ConcurrentIndex | ||
add_index :user_guid, name: :jobs_user_guid_index unless @db.indexes(:jobs).include?(:jobs_user_guid_index) | ||
# rubocop:enable Sequel/ConcurrentIndex | ||
end | ||
end | ||
end | ||
|
||
down do | ||
if database_type == :postgres | ||
alter_table :jobs do | ||
drop_index :user_guid, name: :jobs_user_guid_index, if_exists: true, concurrently: true | ||
drop_column :user_guid, if_exists: true | ||
end | ||
end | ||
|
||
if database_type == :mysql | ||
alter_table :jobs do | ||
# rubocop:disable Sequel/ConcurrentIndex | ||
drop_index :user_guid, name: :jobs_user_guid_index if @db.indexes(:jobs).include?(:jobs_user_guid_index) | ||
# rubocop:enable Sequel/ConcurrentIndex | ||
drop_column :user_guid if @db.schema(:jobs).map(&:first).include?(:user_guid) | ||
end | ||
end | ||
end | ||
end |
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
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
90 changes: 90 additions & 0 deletions
90
spec/migrations/20240314131908_add_user_guid_to_jobs_table_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,90 @@ | ||
require 'spec_helper' | ||
require 'migrations/helpers/migration_shared_context' | ||
|
||
RSpec.describe 'migration to add user_guid column to jobs table and add an index for that column', isolation: :truncation do | ||
include_context 'migration' do | ||
let(:migration_filename) { '20240314131908_add_user_guid_to_jobs_table.rb' } | ||
end | ||
|
||
describe 'jobs table' do | ||
it 'adds a column `user_guid`' do | ||
expect(db[:jobs].columns).not_to include(:user_guid) | ||
expect { Sequel::Migrator.run(db, migration_to_test, allow_missing_migration_files: true) }.not_to raise_error | ||
expect(db[:jobs].columns).to include(:user_guid) | ||
end | ||
|
||
it 'adds an index on the user_guid column' do | ||
expect(db.indexes(:jobs)).not_to include(:jobs_user_guid_index) | ||
expect { Sequel::Migrator.run(db, migration_to_test, allow_missing_migration_files: true) }.not_to raise_error | ||
expect(db.indexes(:jobs)).to include(:jobs_user_guid_index) | ||
end | ||
|
||
describe 'idempotency of up' do | ||
context '`user_guid` column already exists' do | ||
before do | ||
db.add_column :jobs, :user_guid, String, size: 255 | ||
end | ||
|
||
it 'does not fail' do | ||
expect(db[:jobs].columns).to include(:user_guid) | ||
expect { Sequel::Migrator.run(db, migration_to_test, allow_missing_migration_files: true) }.not_to raise_error | ||
end | ||
|
||
it 'continues to create the index' do | ||
expect(db[:jobs].columns).to include(:user_guid) | ||
expect(db.indexes(:jobs)).not_to include(:jobs_user_guid_index) | ||
expect { Sequel::Migrator.run(db, migration_to_test, allow_missing_migration_files: true) }.not_to raise_error | ||
expect(db.indexes(:jobs)).to include(:jobs_user_guid_index) | ||
end | ||
end | ||
|
||
context 'index already exists' do | ||
before do | ||
db.add_column :jobs, :user_guid, String, size: 255 | ||
db.add_index :jobs, :user_guid, name: :jobs_user_guid_index | ||
end | ||
|
||
it 'does not fail' do | ||
expect(db.indexes(:jobs)).to include(:jobs_user_guid_index) | ||
expect { Sequel::Migrator.run(db, migration_to_test, allow_missing_migration_files: true) }.not_to raise_error | ||
end | ||
end | ||
end | ||
|
||
describe 'idempotency of down' do | ||
context 'index does not exist' do | ||
before do | ||
Sequel::Migrator.run(db, migration_to_test, allow_missing_migration_files: true) | ||
db.drop_index :jobs, :user_guid, name: :jobs_user_guid_index | ||
end | ||
|
||
it 'does not fail' do | ||
expect(db[:jobs].columns).to include(:user_guid) | ||
expect(db.indexes(:jobs)).not_to include(:jobs_user_guid_index) | ||
expect { Sequel::Migrator.run(db, migration_to_test, allow_missing_migration_files: true, target: 0) }.not_to raise_error | ||
end | ||
|
||
it 'continues to remove the `user_guid` column' do | ||
expect(db[:jobs].columns).to include(:user_guid) | ||
expect(db.indexes(:jobs)).not_to include(:jobs_user_guid_index) | ||
expect { Sequel::Migrator.run(db, migration_to_test, allow_missing_migration_files: true, target: 0) }.not_to raise_error | ||
expect(db[:jobs].columns).not_to include(:user_guid) | ||
end | ||
end | ||
|
||
context 'index and column do not exist' do | ||
before do | ||
Sequel::Migrator.run(db, migration_to_test, allow_missing_migration_files: true) | ||
db.drop_index :jobs, :user_guid, name: :jobs_user_guid_index | ||
db.drop_column :jobs, :user_guid | ||
end | ||
|
||
it 'does not fail' do | ||
expect(db[:jobs].columns).not_to include(:user_guid) | ||
expect(db.indexes(:jobs)).not_to include(:jobs_user_guid_index) | ||
expect { Sequel::Migrator.run(db, migration_to_test, allow_missing_migration_files: true, target: 0) }.not_to raise_error | ||
end | ||
end | ||
end | ||
end | ||
end |
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
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
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
Oops, something went wrong.