Class: Gitlab::BackgroundMigration::FixUserNamespaceNames
- Inherits:
-
Object
- Object
- Gitlab::BackgroundMigration::FixUserNamespaceNames
- Defined in:
- lib/gitlab/background_migration/fix_user_namespace_names.rb
Overview
This migration fixes the namespaces.name for all user-namespaces that have names that aren't equal to the users name. Then it uses the updated names of the namespaces to update the associated routes For more info see gitlab.com/gitlab-org/gitlab-foss/merge_requests/23272
Instance Method Summary collapse
- #fix_namespace_names(from_id, to_id) ⇒ Object
- #fix_namespace_route_names(from_id, to_id) ⇒ Object
- #perform(from_id, to_id) ⇒ Object
Instance Method Details
#fix_namespace_names(from_id, to_id) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/gitlab/background_migration/fix_user_namespace_names.rb', line 15 def fix_namespace_names(from_id, to_id) ActiveRecord::Base.connection.execute <<~UPDATE_NAMESPACES WITH namespaces_to_update AS ( SELECT namespaces.id, users.name AS correct_name FROM namespaces INNER JOIN users ON namespaces.owner_id = users.id WHERE namespaces.type IS NULL AND namespaces.id BETWEEN #{from_id} AND #{to_id} AND namespaces.name != users.name ) UPDATE namespaces SET name = correct_name FROM namespaces_to_update WHERE namespaces.id = namespaces_to_update.id UPDATE_NAMESPACES end |
#fix_namespace_route_names(from_id, to_id) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/gitlab/background_migration/fix_user_namespace_names.rb', line 40 def fix_namespace_route_names(from_id, to_id) ActiveRecord::Base.connection.execute <<~ROUTES_UPDATE WITH routes_to_update AS ( SELECT routes.id, users.name AS correct_name FROM routes INNER JOIN namespaces ON routes.source_id = namespaces.id INNER JOIN users ON namespaces.owner_id = users.id WHERE namespaces.type IS NULL AND routes.source_type = 'Namespace' AND namespaces.id BETWEEN #{from_id} AND #{to_id} AND (routes.name != users.name OR routes.name IS NULL) ) UPDATE routes SET name = correct_name FROM routes_to_update WHERE routes_to_update.id = routes.id ROUTES_UPDATE end |
#perform(from_id, to_id) ⇒ Object
10 11 12 13 |
# File 'lib/gitlab/background_migration/fix_user_namespace_names.rb', line 10 def perform(from_id, to_id) fix_namespace_names(from_id, to_id) fix_namespace_route_names(from_id, to_id) end |