gitlab-org--gitlab-foss/db/migrate/20190325080727_truncate_user_fullname.rb
Brandon Labuschagne ebfe19e8e7 Add limit of 128 characters to users name
Truncate existing users names which exceed 128 characters
Include test for truncating users names
2019-04-05 09:35:34 +02:00

21 lines
478 B
Ruby

# rubocop:disable Migration/UpdateLargeTable
class TruncateUserFullname < ActiveRecord::Migration[5.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
truncated_name = Arel.sql('SUBSTRING(name from 1 for 128)')
where_clause = Arel.sql("LENGTH(name) > 128")
update_column_in_batches(:users, :name, truncated_name) do |table, query|
query.where(where_clause)
end
end
def down
# noop
end
end