Commit 537b45b7 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Rename users on mysql

parent bc58f51d
...@@ -26,10 +26,21 @@ class RenameUsersWithRenamedNamespace < ActiveRecord::Migration ...@@ -26,10 +26,21 @@ class RenameUsersWithRenamedNamespace < ActiveRecord::Migration
def up def up
DISALLOWED_ROOT_PATHS.each do |path| DISALLOWED_ROOT_PATHS.each do |path|
update_sql = "UPDATE users SET username = namespaces.path "\ users = Arel::Table.new(:users)
"FROM namespaces WHERE namespaces.owner_id = users.id "\ namespaces = Arel::Table.new(:namespaces)
"AND namespaces.type IS NULL "\ predicate = namespaces[:owner_id].eq(users[:id])
"AND users.username ILIKE '#{path}'" .and(namespaces[:type].eq(nil))
.and(users[:username].matches(path))
update_sql = if Gitlab::Database.postgresql?
"UPDATE users SET username = namespaces.path "\
"FROM namespaces WHERE #{predicate.to_sql}"
else
"UPDATE users INNER JOIN namespaces "\
"ON namespaces.owner_id = users.id "\
"SET username = namespaces.path "\
"WHERE #{predicate.to_sql}"
end
connection.execute(update_sql) connection.execute(update_sql)
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment