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
path: root/lib
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2017-05-25 20:22:00 +0300
committerTimothy Andrew <mail@timothyandrew.net>2017-05-31 06:46:45 +0300
commit960d0fda54f75ca6e856686f826cf2ef37d4eff5 (patch)
tree43d8450a1fc8f9b00fa139faecdc30b1046f8db5 /lib
parentd945b21268970fce423adcb003aabe8c86f3adc6 (diff)
Merge branch '28917-contain-uploads-in-system-dir' into 'security'
Upload files into `public/upload/system` instead of `public/upload` See merge request !2073
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/database/migration_helpers.rb25
1 files changed, 24 insertions, 1 deletions
diff --git a/lib/gitlab/database/migration_helpers.rb b/lib/gitlab/database/migration_helpers.rb
index fc445ab9483..2ebf4956a03 100644
--- a/lib/gitlab/database/migration_helpers.rb
+++ b/lib/gitlab/database/migration_helpers.rb
@@ -80,7 +80,7 @@ module Gitlab
# here is based on Rails' foreign_key_name() method, which unfortunately
# is private so we can't rely on it directly.
def concurrent_foreign_key_name(table, column)
- "fk_#{Digest::SHA256.hexdigest("#{table}_#{column}_fk").first(10)}"
+ "fk_#{Digest::SHA256.hexdigest('#{table}_#{column}_fk').first(10)}"
end
# Long-running migrations may take more than the timeout allowed by
@@ -226,6 +226,29 @@ module Gitlab
raise error
end
end
+
+ # This will replace the first occurance of a string in a column with
+ # the replacement
+ # On postgresql we can use `regexp_replace` for that.
+ # On mysql we find the location of the pattern, and overwrite it
+ # with the replacement
+ def replace_sql(column, pattern, replacement)
+ quoted_pattern = Arel::Nodes::Quoted.new(pattern.to_s)
+ quoted_replacement = Arel::Nodes::Quoted.new(replacement.to_s)
+
+ if Database.mysql?
+ locate = Arel::Nodes::NamedFunction.
+ new('locate', [quoted_pattern, column])
+ insert_in_place = Arel::Nodes::NamedFunction.
+ new('insert', [column, locate, pattern.size, quoted_replacement])
+
+ Arel::Nodes::SqlLiteral.new(insert_in_place.to_sql)
+ else
+ replace = Arel::Nodes::NamedFunction.
+ new("regexp_replace", [column, quoted_pattern, quoted_replacement])
+ Arel::Nodes::SqlLiteral.new(replace.to_sql)
+ end
+ end
end
end
end