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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-06-18 14:18:50 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-06-18 14:18:50 +0300
commit8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781 (patch)
treea77e7fe7a93de11213032ed4ab1f33a3db51b738 /db/post_migrate/20200602013901_cap_designs_filename_length_to_new_limit.rb
parent00b35af3db1abfe813a778f643dad221aad51fca (diff)
Add latest changes from gitlab-org/gitlab@13-1-stable-ee
Diffstat (limited to 'db/post_migrate/20200602013901_cap_designs_filename_length_to_new_limit.rb')
-rw-r--r--db/post_migrate/20200602013901_cap_designs_filename_length_to_new_limit.rb40
1 files changed, 40 insertions, 0 deletions
diff --git a/db/post_migrate/20200602013901_cap_designs_filename_length_to_new_limit.rb b/db/post_migrate/20200602013901_cap_designs_filename_length_to_new_limit.rb
new file mode 100644
index 00000000000..0458481c6bd
--- /dev/null
+++ b/db/post_migrate/20200602013901_cap_designs_filename_length_to_new_limit.rb
@@ -0,0 +1,40 @@
+# frozen_string_literal: true
+
+class CapDesignsFilenameLengthToNewLimit < ActiveRecord::Migration[6.0]
+ DOWNTIME = false
+
+ CHAR_LENGTH = 255
+ MODIFIED_NAME = 'gitlab-modified-'
+ MODIFIED_EXTENSION = '.jpg'
+
+ def up
+ arel_table = Arel::Table.new(:design_management_designs)
+
+ # Design filenames larger than the limit will be renamed to "gitlab-modified-{id}.jpg",
+ # which will be valid and unique. The design file itself will appear broken, as it is
+ # understood that no designs with filenames that exceed this limit will be legitimate.
+ # See https://gitlab.com/gitlab-org/gitlab/-/merge_requests/33565/diffs#note_355789080
+ new_value_clause = Arel::Nodes::NamedFunction.new(
+ 'CONCAT',
+ [
+ Arel::Nodes.build_quoted(MODIFIED_NAME),
+ arel_table[:id],
+ Arel::Nodes.build_quoted(MODIFIED_EXTENSION)
+ ]
+ )
+ where_clause = Arel::Nodes::NamedFunction.new(
+ 'CHAR_LENGTH',
+ [arel_table[:filename]]
+ ).gt(CHAR_LENGTH)
+
+ update_arel = Arel::UpdateManager.new.table(arel_table)
+ .set([[arel_table[:filename], new_value_clause]])
+ .where(where_clause)
+
+ ActiveRecord::Base.connection.execute(update_arel.to_sql)
+ end
+
+ def down
+ # no-op : the original filename is lost forever
+ end
+end