summaryrefslogtreecommitdiff
path: root/db/migrate
diff options
context:
space:
mode:
authorAndreas Brandl <abrandl@gitlab.com>2019-04-05 11:29:19 +0000
committerAndreas Brandl <abrandl@gitlab.com>2019-04-05 11:29:19 +0000
commit30fa3cbdb74df2dfeebb2929a10dd301a0dde55e (patch)
tree72b5a7d8d615475ea2b8afabbfcebe1402c96d52 /db/migrate
parent14cf8bf050896d617761e7947f81c8e23364a48b (diff)
parentebfe19e8e7690598f86facc0bb18df4052468fc0 (diff)
downloadgitlab-ce-30fa3cbdb74df2dfeebb2929a10dd301a0dde55e.tar.gz
Merge branch '57493-add-limit-to-user-name' into 'master'
Add a length limit of 128 char to the user name field See merge request gitlab-org/gitlab-ce!26146
Diffstat (limited to 'db/migrate')
-rw-r--r--db/migrate/20190325080727_truncate_user_fullname.rb21
1 files changed, 21 insertions, 0 deletions
diff --git a/db/migrate/20190325080727_truncate_user_fullname.rb b/db/migrate/20190325080727_truncate_user_fullname.rb
new file mode 100644
index 00000000000..e5f88671eef
--- /dev/null
+++ b/db/migrate/20190325080727_truncate_user_fullname.rb
@@ -0,0 +1,21 @@
+# 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