diff options
author | Kamil Trzciński <ayufan@ayufan.eu> | 2018-03-29 10:58:21 +0000 |
---|---|---|
committer | Kamil Trzciński <ayufan@ayufan.eu> | 2018-03-29 10:58:21 +0000 |
commit | 8230b774b5a6375d9b84c71e72c8e41e3bfd7fad (patch) | |
tree | 151480556851e0c9b3fd233eb8e9bb0459d7ee6e | |
parent | 8b37ce6f7f6d29604c42c65f3986d60dce0abd6c (diff) | |
parent | d756150dcf9d078c9bc27316b0ce7937df427266 (diff) | |
download | gitlab-ce-8230b774b5a6375d9b84c71e72c8e41e3bfd7fad.tar.gz |
Merge branch 'fix/gb/fix-background-pipeline-stages-migration' into 'master'
Fix background pipeline stages migration
Closes #44135
See merge request gitlab-org/gitlab-ce!18076
4 files changed, 26 insertions, 1 deletions
diff --git a/changelogs/unreleased/fix-gb-fix-background-pipeline-stages-migration.yml b/changelogs/unreleased/fix-gb-fix-background-pipeline-stages-migration.yml new file mode 100644 index 00000000000..63948f0c196 --- /dev/null +++ b/changelogs/unreleased/fix-gb-fix-background-pipeline-stages-migration.yml @@ -0,0 +1,5 @@ +--- +title: Fix exceptions raised when migrating pipeline stages in the background +merge_request: 18076 +author: +type: fixed diff --git a/lib/gitlab/background_migration/migrate_build_stage.rb b/lib/gitlab/background_migration/migrate_build_stage.rb index 8fe4f1a2289..242e3143e71 100644 --- a/lib/gitlab/background_migration/migrate_build_stage.rb +++ b/lib/gitlab/background_migration/migrate_build_stage.rb @@ -12,6 +12,7 @@ module Gitlab class Build < ActiveRecord::Base self.table_name = 'ci_builds' + self.inheritance_column = :_type_disabled def ensure_stage!(attempts: 2) find_stage || create_stage! diff --git a/spec/lib/gitlab/background_migration/migrate_build_stage_spec.rb b/spec/lib/gitlab/background_migration/migrate_build_stage_spec.rb index e112e9e9e3d..5ce84c61042 100644 --- a/spec/lib/gitlab/background_migration/migrate_build_stage_spec.rb +++ b/spec/lib/gitlab/background_migration/migrate_build_stage_spec.rb @@ -51,4 +51,20 @@ describe Gitlab::BackgroundMigration::MigrateBuildStage, :migration, schema: 201 expect { described_class.new.perform(1, 6) } .to raise_error ActiveRecord::RecordNotUnique end + + context 'when invalid class can be loaded due to single table inheritance' do + let(:commit_status) do + jobs.create!(id: 7, commit_id: 1, project_id: 123, stage_idx: 4, + stage: 'post-deploy', status: :failed) + end + + before do + commit_status.update_column(:type, 'SomeClass') + end + + it 'does ignore single table inheritance type' do + expect { described_class.new.perform(1, 7) }.not_to raise_error + expect(jobs.find(7)).to have_attributes(stage_id: (a_value > 0)) + end + end end diff --git a/spec/support/migrations_helpers.rb b/spec/support/migrations_helpers.rb index 6bf976a2cf9..5d6f662e8fe 100644 --- a/spec/support/migrations_helpers.rb +++ b/spec/support/migrations_helpers.rb @@ -1,6 +1,9 @@ module MigrationsHelpers def table(name) - Class.new(ActiveRecord::Base) { self.table_name = name } + Class.new(ActiveRecord::Base) do + self.table_name = name + self.inheritance_column = :_type_disabled + end end def migrations_paths |