summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
authorBob Van Landuyt <bob@gitlab.com>2017-05-19 17:22:45 +0200
committerBob Van Landuyt <bob@gitlab.com>2017-05-19 17:27:18 +0200
commit51913c32bab12ec366cc3c529f2ed3d6699ee25e (patch)
tree602cf56e5941624487f8ef0f8c1129adcea6ba4c /db
parent84f8cd1718857b4ee75fa6bd4b2fdb4879846bcf (diff)
downloadgitlab-ce-51913c32bab12ec366cc3c529f2ed3d6699ee25e.tar.gz
Simpler way of renaming users
Diffstat (limited to 'db')
-rw-r--r--db/post_migrate/20170518200835_rename_users_with_renamed_namespace.rb15
1 files changed, 6 insertions, 9 deletions
diff --git a/db/post_migrate/20170518200835_rename_users_with_renamed_namespace.rb b/db/post_migrate/20170518200835_rename_users_with_renamed_namespace.rb
index a0444f4cc62..dfb8a020119 100644
--- a/db/post_migrate/20170518200835_rename_users_with_renamed_namespace.rb
+++ b/db/post_migrate/20170518200835_rename_users_with_renamed_namespace.rb
@@ -26,15 +26,12 @@ class RenameUsersWithRenamedNamespace < ActiveRecord::Migration
]
def up
- namespace_table = Arel::Table.new('namespaces')
- users_table = Arel::Table.new('users')
- matching_path = namespace_table.project(namespace_table[:path])
- .join(users_table).on(users_table[:id].eq(namespace_table[:owner_id]))
- .where(users_table[:username].not_eq(namespace_table[:path]))
- path_name = Arel::Nodes::SqlLiteral.new("matching_path.path FROM (#{matching_path.to_sql}) as matching_path")
-
- update_column_in_batches(:users, :username, path_name) do |table, query|
- query.where(table[:username].matches_any(DISALLOWED_ROOT_PATHS))
+ DISALLOWED_ROOT_PATHS.each do |path|
+ update_sql = "UPDATE users SET username = namespaces.path "\
+ "FROM namespaces WHERE namespaces.owner_id = users.id "\
+ "AND namespaces.type IS NULL "\
+ "AND users.username ILIKE '#{path}'"
+ connection.execute(update_sql)
end
end