Commit 0e34b09e authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Merge branch '241492-increase-pypi-version-size' into 'master'

Increase pypi required_python field size to 255

Closes #241492

See merge request gitlab-org/gitlab!41018
parents 7ae4af48 d0b3ba56
......@@ -6,7 +6,7 @@ class Packages::Pypi::Metadatum < ApplicationRecord
belongs_to :package, -> { where(package_type: :pypi) }, inverse_of: :pypi_metadatum
validates :package, presence: true
validates :required_python, length: { maximum: 50 }, allow_blank: true
validates :required_python, length: { maximum: 255 }, allow_blank: true
validate :pypi_package_type
......
---
title: Increase Pypi required_version limit to 255
merge_request: 41018
author:
type: changed
# frozen_string_literal: true
class ChangePypiPythonVersionType < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
change_column_type_concurrently :packages_pypi_metadata, :required_python, :text, batch_column_name: :package_id # rubocop:disable Migration/AddLimitToTextColumns
end
def down
cleanup_concurrent_column_type_change(:packages_pypi_metadata, :required_python)
change_column_null :packages_pypi_metadata, :required_python, false
end
end
# frozen_string_literal: true
class ChangePypiPythonVersionTypeCleanup < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
cleanup_concurrent_column_type_change(:packages_pypi_metadata, :required_python)
end
def down
execute('UPDATE packages_pypi_metadata SET required_python = substring(required_python from 1 for 50)')
change_column_type_concurrently :packages_pypi_metadata, :required_python, 'varchar(50)', batch_column_name: :package_id
end
end
# frozen_string_literal: true
class IncreasePypiVersionSize < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
add_text_limit :packages_pypi_metadata, :required_python, 255
end
def down
remove_text_limit :packages_pypi_metadata, :required_python
end
end
b196c8ce85631432e712a977b09cdba70872f42b16bca53eda1bc8558f57ea24
\ No newline at end of file
9579a789ed6256a513a7afb51eeaf11661d1ef2e5d8312e28a69579eb39d8960
\ No newline at end of file
c0f798f6ffd8d67137e6076242f5fb0004736f03c9cde5556dec228eefa75cb1
\ No newline at end of file
......@@ -14085,7 +14085,9 @@ ALTER SEQUENCE public.packages_packages_id_seq OWNED BY public.packages_packages
CREATE TABLE public.packages_pypi_metadata (
package_id bigint NOT NULL,
required_python character varying(50) NOT NULL
required_python text,
CONSTRAINT check_0d9aed55b2 CHECK ((required_python IS NOT NULL)),
CONSTRAINT check_379019d5da CHECK ((char_length(required_python) <= 255))
);
CREATE TABLE public.packages_tags (
......
......@@ -538,10 +538,10 @@ module Gitlab
# table - The table containing the column.
# column - The name of the column to change.
# new_type - The new column type.
def change_column_type_concurrently(table, column, new_type, type_cast_function: nil)
def change_column_type_concurrently(table, column, new_type, type_cast_function: nil, batch_column_name: :id)
temp_column = "#{column}_for_type_change"
rename_column_concurrently(table, column, temp_column, type: new_type, type_cast_function: type_cast_function)
rename_column_concurrently(table, column, temp_column, type: new_type, type_cast_function: type_cast_function, batch_column_name: batch_column_name)
end
# Performs cleanup of a concurrent type change.
......
......@@ -903,15 +903,22 @@ RSpec.describe Gitlab::Database::MigrationHelpers do
describe '#change_column_type_concurrently' do
it 'changes the column type' do
expect(model).to receive(:rename_column_concurrently)
.with('users', 'username', 'username_for_type_change', type: :text, type_cast_function: nil)
.with('users', 'username', 'username_for_type_change', type: :text, type_cast_function: nil, batch_column_name: :id)
model.change_column_type_concurrently('users', 'username', :text)
end
it 'passed the batch column name' do
expect(model).to receive(:rename_column_concurrently)
.with('users', 'username', 'username_for_type_change', type: :text, type_cast_function: nil, batch_column_name: :user_id)
model.change_column_type_concurrently('users', 'username', :text, batch_column_name: :user_id)
end
context 'with type cast' do
it 'changes the column type with casting the value to the new type' do
expect(model).to receive(:rename_column_concurrently)
.with('users', 'username', 'username_for_type_change', type: :text, type_cast_function: 'JSON')
.with('users', 'username', 'username_for_type_change', type: :text, type_cast_function: 'JSON', batch_column_name: :id)
model.change_column_type_concurrently('users', 'username', :text, type_cast_function: 'JSON')
end
......
......@@ -176,7 +176,7 @@ RSpec.describe API::PypiPackages do
end
context 'with required_python too big' do
let(:requires_python) { 'x' * 51 }
let(:requires_python) { 'x' * 256 }
let(:token) { personal_access_token.token }
let(:user_headers) { basic_auth_header(user.username, token) }
let(:headers) { user_headers.merge(workhorse_header) }
......
......@@ -40,7 +40,7 @@ RSpec.describe Packages::Pypi::CreatePackageService do
end
context 'with an invalid metadata' do
let(:requires_python) { 'x' * 51 }
let(:requires_python) { 'x' * 256 }
it 'raises an error' do
expect { subject }.to raise_error(ActiveRecord::RecordInvalid)
......
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