Commit 92b5d14b authored by Valery Sizov's avatar Valery Sizov Committed by Adam Hegyi

Change the type of verification_checksum column

in package file table for efficient usage of DB space
parent 3a4ca8d6
# frozen_string_literal: true
class ChangeVerificationChecksumFieldTypeInPackageFile < ActiveRecord::Migration[6.0]
DOWNTIME = false
def up
# The use of this column is behind a feature flag that never got enabled,
# so it's safe to remove it in a normal migration
remove_column :packages_package_files, :verification_checksum, :string # rubocop:disable Migration/RemoveColumn
add_column :packages_package_files, :verification_checksum, :binary
end
def down
remove_column :packages_package_files, :verification_checksum, :binary
add_column :packages_package_files, :verification_checksum, :string
end
end
# frozen_string_literal: true
class AddChecksumIndexToPackageFile < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
add_concurrent_index :packages_package_files, :verification_checksum, where: "(verification_checksum IS NOT NULL)", name: "packages_packages_verification_checksum_partial"
end
def down
remove_concurrent_index :packages_package_files, :verification_checksum
end
end
......@@ -4668,9 +4668,9 @@ CREATE TABLE public.packages_package_files (
file_sha256 bytea,
verification_retry_at timestamp with time zone,
verified_at timestamp with time zone,
verification_checksum character varying(255),
verification_failure character varying(255),
verification_retry_count integer
verification_retry_count integer,
verification_checksum bytea
);
CREATE SEQUENCE public.packages_package_files_id_seq
......@@ -13738,6 +13738,8 @@ COPY "schema_migrations" (version) FROM STDIN;
20200408175424
20200408212219
20200409085956
20200409105455
20200409105456
20200409211607
20200410104828
20200410232012
......
......@@ -324,7 +324,7 @@ Widgets should now be replicated by Geo!
def change
add_column :widgets, :verification_retry_at, :datetime_with_timezone
add_column :widgets, :verified_at, :datetime_with_timezone
add_column :widgets, :verification_checksum, :string
add_column :widgets, :verification_checksum, :binary, using: 'verification_checksum::bytea'
add_column :widgets, :verification_failure, :string
add_column :widgets, :verification_retry_count, :integer
end
......
......@@ -5,6 +5,7 @@ module Gitlab
module ReplicableModel
extend ActiveSupport::Concern
include Checksummable
include ::ShaAttribute
included do
# If this hook turns out not to apply to all Models, perhaps we should extract a `ReplicableBlobModel`
......@@ -12,6 +13,8 @@ module Gitlab
scope :checksummed, -> { where('verification_checksum IS NOT NULL') }
scope :checksum_failed, -> { where('verification_failure IS NOT NULL') }
sha_attribute :verification_checksum
end
class_methods do
......
......@@ -10,7 +10,9 @@ describe Gitlab::Geo::Replicator do
before(:all) do
ActiveRecord::Schema.define do
create_table :dummy_models
create_table :dummy_models, force: true do |t|
t.binary :verification_checksum
end
end
end
......@@ -70,6 +72,8 @@ describe Gitlab::Geo::Replicator do
with_replicator Geo::DummyReplicator
end
DummyModel.reset_column_information
end
subject { DummyModel.new }
......
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