Commit d0b3ba56 authored by Giorgenes Gelatti's avatar Giorgenes Gelatti

Increase pypi required_python size to 255

Adds migration to increase column limit
and update specs.
parent 8e43527d
...@@ -6,7 +6,7 @@ class Packages::Pypi::Metadatum < ApplicationRecord ...@@ -6,7 +6,7 @@ class Packages::Pypi::Metadatum < ApplicationRecord
belongs_to :package, -> { where(package_type: :pypi) }, inverse_of: :pypi_metadatum belongs_to :package, -> { where(package_type: :pypi) }, inverse_of: :pypi_metadatum
validates :package, presence: true 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 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
...@@ -14084,7 +14084,9 @@ ALTER SEQUENCE public.packages_packages_id_seq OWNED BY public.packages_packages ...@@ -14084,7 +14084,9 @@ ALTER SEQUENCE public.packages_packages_id_seq OWNED BY public.packages_packages
CREATE TABLE public.packages_pypi_metadata ( CREATE TABLE public.packages_pypi_metadata (
package_id bigint NOT NULL, 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 ( CREATE TABLE public.packages_tags (
......
...@@ -538,10 +538,10 @@ module Gitlab ...@@ -538,10 +538,10 @@ module Gitlab
# table - The table containing the column. # table - The table containing the column.
# column - The name of the column to change. # column - The name of the column to change.
# new_type - The new column type. # 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" 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 end
# Performs cleanup of a concurrent type change. # Performs cleanup of a concurrent type change.
......
...@@ -903,15 +903,22 @@ RSpec.describe Gitlab::Database::MigrationHelpers do ...@@ -903,15 +903,22 @@ RSpec.describe Gitlab::Database::MigrationHelpers do
describe '#change_column_type_concurrently' do describe '#change_column_type_concurrently' do
it 'changes the column type' do it 'changes the column type' do
expect(model).to receive(:rename_column_concurrently) 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) model.change_column_type_concurrently('users', 'username', :text)
end 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 context 'with type cast' do
it 'changes the column type with casting the value to the new type' do it 'changes the column type with casting the value to the new type' do
expect(model).to receive(:rename_column_concurrently) 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') model.change_column_type_concurrently('users', 'username', :text, type_cast_function: 'JSON')
end end
......
...@@ -176,7 +176,7 @@ RSpec.describe API::PypiPackages do ...@@ -176,7 +176,7 @@ RSpec.describe API::PypiPackages do
end end
context 'with required_python too big' do context 'with required_python too big' do
let(:requires_python) { 'x' * 51 } let(:requires_python) { 'x' * 256 }
let(:token) { personal_access_token.token } let(:token) { personal_access_token.token }
let(:user_headers) { basic_auth_header(user.username, token) } let(:user_headers) { basic_auth_header(user.username, token) }
let(:headers) { user_headers.merge(workhorse_header) } let(:headers) { user_headers.merge(workhorse_header) }
......
...@@ -40,7 +40,7 @@ RSpec.describe Packages::Pypi::CreatePackageService do ...@@ -40,7 +40,7 @@ RSpec.describe Packages::Pypi::CreatePackageService do
end end
context 'with an invalid metadata' do context 'with an invalid metadata' do
let(:requires_python) { 'x' * 51 } let(:requires_python) { 'x' * 256 }
it 'raises an error' do it 'raises an error' do
expect { subject }.to raise_error(ActiveRecord::RecordInvalid) 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