diff options
author | Bob Van Landuyt <bob@gitlab.com> | 2017-06-23 21:59:38 +0300 |
---|---|---|
committer | Bob Van Landuyt <bob@vanlanduyt.co> | 2017-06-26 18:49:30 +0300 |
commit | 60561aca22f7abbace1b46bc8312cd2192c02344 (patch) | |
tree | d28d4048ba01f416a1b07b3dd7c425efac34719f /lib/gitlab/database | |
parent | 79cdacc5d464cfb47076efe27e3d6ffe32ff1dad (diff) |
Update routes directly by ID instead of filtering by path
Diffstat (limited to 'lib/gitlab/database')
-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) |