Commit 45cc048e authored by Grzegorz Bizon's avatar Grzegorz Bizon

Merge branch 'feature/gb/protected-attribute-in-pending-builds' into 'master'

Add protected pending build column and migrate data

See merge request gitlab-org/gitlab!63759
parents ea9f1b3b a6f7c67c
......@@ -8,7 +8,7 @@ module Ci
belongs_to :build, class_name: 'Ci::Build'
def self.upsert_from_build!(build)
entry = self.new(build: build, project: build.project)
entry = self.new(build: build, project: build.project, protected: build.protected?)
entry.validate!
......
# frozen_string_literal: true
class AddProtectedAttributeToPendingBuilds < ActiveRecord::Migration[6.1]
def change
add_column :ci_pending_builds, :protected, :boolean, null: false, default: false
end
end
# frozen_string_literal: true
class MigrateProtectedAttributeToPendingBuilds < ActiveRecord::Migration[6.1]
include ::Gitlab::Database::DynamicModelHelpers
disable_ddl_transaction!
def up
return unless Gitlab.dev_or_test_env? || Gitlab.com?
each_batch_range('ci_pending_builds', of: 1000) do |min, max|
execute <<~SQL
UPDATE ci_pending_builds
SET protected = true
FROM ci_builds
WHERE ci_pending_builds.build_id = ci_builds.id
AND ci_builds.protected = true
AND ci_pending_builds.id BETWEEN #{min} AND #{max}
SQL
end
end
def down
# no op
end
end
# frozen_string_literal: true
class AddIndexToProtectedPendingBuilds < ActiveRecord::Migration[6.1]
include Gitlab::Database::MigrationHelpers
INDEX_NAME = 'index_ci_pending_builds_id_on_protected_partial'
disable_ddl_transaction!
def up
add_concurrent_index :ci_pending_builds, :id, where: 'protected = true', name: INDEX_NAME
end
def down
remove_concurrent_index_by_name :ci_pending_builds, INDEX_NAME
end
end
dab13c78f6f758c63be923277c0f31e4cce4e30f77a8dc2983a9bb1500a454f9
\ No newline at end of file
ce21070d44a34081c6babd14e6a1b607bad5ed9047b18f4ef0beb64b5a2ce120
\ No newline at end of file
3ad279a7c57e433a8ee349dabd2536c1de9055936b05c26b5469606067eb90d4
\ No newline at end of file
......@@ -10799,7 +10799,8 @@ CREATE TABLE ci_pending_builds (
id bigint NOT NULL,
build_id bigint NOT NULL,
project_id bigint NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL
created_at timestamp with time zone DEFAULT now() NOT NULL,
protected boolean DEFAULT false NOT NULL
);
CREATE SEQUENCE ci_pending_builds_id_seq
......@@ -22780,6 +22781,8 @@ CREATE UNIQUE INDEX index_ci_pending_builds_on_build_id ON ci_pending_builds USI
CREATE INDEX index_ci_pending_builds_on_project_id ON ci_pending_builds USING btree (project_id);
CREATE INDEX index_ci_pending_builds_on_protected ON ci_pending_builds USING btree (protected);
CREATE INDEX index_ci_pipeline_artifacts_failed_verification ON ci_pipeline_artifacts USING btree (verification_retry_at NULLS FIRST) WHERE (verification_state = 3);
CREATE INDEX index_ci_pipeline_artifacts_needs_verification ON ci_pipeline_artifacts USING btree (verification_state) WHERE ((verification_state = 0) OR (verification_state = 3));
# frozen_string_literal: true
require 'spec_helper'
require Rails.root.join('db', 'post_migrate', '20210610102413_migrate_protected_attribute_to_pending_builds.rb')
RSpec.describe MigrateProtectedAttributeToPendingBuilds do
let(:namespaces) { table(:namespaces) }
let(:projects) { table(:projects) }
let(:queue) { table(:ci_pending_builds) }
let(:builds) { table(:ci_builds) }
before do
namespaces.create!(id: 123, name: 'sample', path: 'sample')
projects.create!(id: 123, name: 'sample', path: 'sample', namespace_id: 123)
builds.create!(id: 1, project_id: 123, status: 'pending', protected: false, type: 'Ci::Build')
builds.create!(id: 2, project_id: 123, status: 'pending', protected: true, type: 'Ci::Build')
builds.create!(id: 3, project_id: 123, status: 'pending', protected: false, type: 'Ci::Build')
builds.create!(id: 4, project_id: 123, status: 'pending', protected: true, type: 'Ci::Bridge')
builds.create!(id: 5, project_id: 123, status: 'success', protected: true, type: 'Ci::Build')
queue.create!(id: 1, project_id: 123, build_id: 1)
queue.create!(id: 2, project_id: 123, build_id: 2)
queue.create!(id: 3, project_id: 123, build_id: 3)
end
it 'updates entries that should be protected' do
migrate!
expect(queue.where(protected: true).count).to eq 1
expect(queue.find_by(protected: true).id).to eq 2
end
end
......@@ -20,7 +20,7 @@ RSpec.describe Ci::PendingBuild do
context 'when another queuing entry exists for given build' do
before do
described_class.create!(build: build, project: project)
described_class.create!(build: build, project: project, protected: false)
end
it 'returns a build id as a result' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment