Commit 8498d108 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Add protected pending build column and migrate data

Changelog: performance
parent 3c580c1a
# 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
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
dab13c78f6f758c63be923277c0f31e4cce4e30f77a8dc2983a9bb1500a454f9
\ No newline at end of file
ce21070d44a34081c6babd14e6a1b607bad5ed9047b18f4ef0beb64b5a2ce120
\ No newline at end of file
......@@ -10838,7 +10838,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
# 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
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