diff options
author | Bob Van Landuyt <bob@gitlab.com> | 2017-06-23 20:59:38 +0200 |
---|---|---|
committer | Bob Van Landuyt <bob@vanlanduyt.co> | 2017-06-26 17:49:30 +0200 |
commit | 60561aca22f7abbace1b46bc8312cd2192c02344 (patch) | |
tree | d28d4048ba01f416a1b07b3dd7c425efac34719f /lib | |
parent | 79cdacc5d464cfb47076efe27e3d6ffe32ff1dad (diff) | |
download | gitlab-ce-60561aca22f7abbace1b46bc8312cd2192c02344.tar.gz |
Update routes directly by ID instead of filtering by path
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/database/rename_reserved_paths_migration/v1/rename_base.rb | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_base.rb b/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_base.rb index 74f6984a6bb..c7ce9749eba 100644 --- a/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_base.rb +++ b/lib/gitlab/database/rename_reserved_paths_migration/v1/rename_base.rb @@ -6,6 +6,7 @@ module Gitlab attr_reader :paths, :migration delegate :update_column_in_batches, + :execute, :replace_sql, :say, to: :migration @@ -42,14 +43,21 @@ module Gitlab end def rename_routes(old_full_path, new_full_path) + routes = Route.arel_table + main_route_ids = routes.project(routes[:id]).where(routes[:path].matches(old_full_path)) + child_route_ids = routes.project(routes[:id]).where(routes[:path].matches("#{old_full_path}/%")) + matching_ids = main_route_ids.union(child_route_ids) + ids = execute(matching_ids.to_sql).map { |entry| entry['id'] } + replace_statement = replace_sql(Route.arel_table[:path], old_full_path, new_full_path) - update_column_in_batches(:routes, :path, replace_statement) do |table, query| - path_or_children = table[:path].matches_any([old_full_path, "#{old_full_path}/%"]) - query.where(path_or_children) - end + update = Arel::UpdateManager.new(ActiveRecord::Base) + .table(routes) + .set([[routes[:path], replace_statement]]) + .where(routes[:id].in(ids)) + execute(update.to_sql) end def rename_path(namespace_path, path_was) |