Commit c96f3dae authored by Tiger Watson's avatar Tiger Watson

Merge branch '324206-processing-package-scope-removal' into 'master'

Update old temporary NuGet packages to processing

See merge request gitlab-org/gitlab!61724
parents 946dbc62 5ea380ea
---
title: Update temporary NuGet packages to have processing status
merge_request: 61724
author:
type: other
# frozen_string_literal: true
class AddTemporaryPackageIndexForNugetDataMigration < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
INDEX_NAME = 'tmp_index_packages_on_id_where_nuget_default_temp_package'
INDEX_CONDITION = "package_type = 4 AND name = 'NuGet.Temporary.Package' AND status = 0"
disable_ddl_transaction!
def up
# this index is used in 20210513155546_backfill_nuget_temporary_packages_to_processing_status
add_concurrent_index :packages_packages, :id, where: INDEX_CONDITION, name: INDEX_NAME
end
def down
remove_concurrent_index_by_name :packages_packages, INDEX_NAME
end
end
# frozen_string_literal: true
class BackfillNugetTemporaryPackagesToProcessingStatus < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
disable_ddl_transaction!
class Package < ActiveRecord::Base
include EachBatch
self.table_name = 'packages_packages'
scope :nuget_temporary_packages, -> do
# 4 is nuget package type, 0 is default status
where(package_type: 4, name: 'NuGet.Temporary.Package', status: 0)
end
end
def up
Package.nuget_temporary_packages.each_batch(of: 100) do |batch|
# 2 is processing status
batch.update_all(status: 2)
end
end
def down
# no-op
end
end
# frozen_string_literal: true
class RemoveTemporaryPackageIndexForNugetDataMigration < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
INDEX_NAME = 'tmp_index_packages_on_id_where_nuget_default_temp_package'
INDEX_CONDITION = "package_type = 4 AND name = 'NuGet.Temporary.Package' AND status = 0"
disable_ddl_transaction!
def up
# this index was used in 20210513155546_backfill_nuget_temporary_packages_to_processing_status
remove_concurrent_index_by_name :packages_packages, INDEX_NAME
end
def down
add_concurrent_index :packages_packages, :id, where: INDEX_CONDITION, name: INDEX_NAME
end
end
1f5ea8527107d4cffac535b9ae3e532a98ebd69a8711abdbe68b12fe005dfbb5
\ No newline at end of file
44abbe007dae17982f923b1b15fd0534d3d3a7fd154cd9e4b5409f86030de2f7
\ No newline at end of file
d1fccf214f2e237482fc4d9e2b5d5ea6e9241ad4ace8739e7b799555afafa215
\ No newline at end of file
# frozen_string_literal: true
require 'spec_helper'
require_migration!
RSpec.describe BackfillNugetTemporaryPackagesToProcessingStatus, :migration do
let(:namespaces) { table(:namespaces) }
let(:projects) { table(:projects) }
let(:packages) { table(:packages_packages) }
before do
namespace = namespaces.create!(id: 123, name: 'test_namespace', path: 'test_namespace')
project = projects.create!(id: 111, name: 'sample_project', path: 'sample_project', namespace_id: namespace.id)
packages.create!(name: 'NuGet.Temporary.Package', version: '0.1.1', package_type: 4, status: 0, project_id: project.id)
packages.create!(name: 'foo', version: '0.1.1', package_type: 4, status: 0, project_id: project.id)
packages.create!(name: 'NuGet.Temporary.Package', version: '0.1.1', package_type: 4, status: 2, project_id: project.id)
packages.create!(name: 'NuGet.Temporary.Package', version: '0.1.1', package_type: 1, status: 2, project_id: project.id)
packages.create!(name: 'NuGet.Temporary.Package', version: '0.1.1', package_type: 1, status: 0, project_id: project.id)
end
it 'updates the applicable packages to processing status', :aggregate_failures do
expect(packages.where(status: 0).count).to eq(3)
expect(packages.where(status: 2).count).to eq(2)
expect(packages.where(name: 'NuGet.Temporary.Package', package_type: 4, status: 0).count).to eq(1)
migrate!
expect(packages.where(status: 0).count).to eq(2)
expect(packages.where(status: 2).count).to eq(3)
expect(packages.where(name: 'NuGet.Temporary.Package', package_type: 4, status: 0).count).to eq(0)
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