Welcome to mirror list, hosted at ThFree Co, Russian Federation.

20190325080727_truncate_user_fullname.rb « migrate « db - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 29255d173d8374ad2cfc8842ca44a61428eccefe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# frozen_string_literal: true

# 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