Fix state value in the lfs_object_registry table

The new state column in the `lfs_objects_registry`
table is set to 0 by default which means pending
that causes Geo to redownload each LFS file.

Changelog: fixed
EE: true
parent 336e847d
# frozen_string_literal: true
class FixStateColumnInLfsObjectRegistry < ActiveRecord::Migration[6.1]
include Gitlab::Database::MigrationHelpers
disable_ddl_transaction!
# The following cop is disabled because of https://gitlab.com/gitlab-org/gitlab/issues/33470
# rubocop:disable Migration/UpdateColumnInBatches
def up
update_column_in_batches(:lfs_object_registry, :state, 2) do |table, query|
query.where(table[:success].eq(true)) # rubocop:disable CodeReuse/ActiveRecord
end
end
# rubocop:enable Migration/UpdateColumnInBatches
def down
# no-op
end
end
......@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2021_05_05_170208) do
ActiveRecord::Schema.define(version: 2021_06_24_160455) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
......
# frozen_string_literal: true
require 'spec_helper'
require_migration!
RSpec.describe FixStateColumnInLfsObjectRegistry do
let(:registry) { table(:lfs_object_registry) }
before do
registry.create!(lfs_object_id: 1, state: 0, success: false)
registry.create!(lfs_object_id: 2, state: 0, success: true)
registry.create!(lfs_object_id: 3, state: 1, success: false)
registry.create!(lfs_object_id: 4, state: 2, success: true)
registry.create!(lfs_object_id: 5, state: 3, success: false)
end
it 'correctly sets registry state value' do
pending_registries = registry.where(state: 0)
synced_registries = registry.where(state: 2)
expect(pending_registries.pluck(:id)).to contain_exactly(1, 2)
expect(synced_registries.pluck(:id)).to contain_exactly(4)
migrate!
expect(pending_registries.pluck(:id)).to contain_exactly(1)
expect(synced_registries.pluck(:id)).to contain_exactly(2, 4)
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