diff options
author | Bob Van Landuyt <bob@gitlab.com> | 2017-05-19 20:11:03 +0200 |
---|---|---|
committer | Bob Van Landuyt <bob@gitlab.com> | 2017-05-19 21:21:32 +0200 |
commit | 537b45b7fbe28efe529555a5a9ac25fad0cb7667 (patch) | |
tree | aadc0b4d288613b41f90ce89cf54f67172b59917 /db | |
parent | bc58f51d14aff86789dd5356245f1a8105aa8995 (diff) | |
download | gitlab-ce-537b45b7fbe28efe529555a5a9ac25fad0cb7667.tar.gz |
Rename users on mysqlbvl-fix-already-renamed-paths
Diffstat (limited to 'db')
-rw-r--r-- | db/post_migrate/20170518200835_rename_users_with_renamed_namespace.rb | 19 |
1 files changed, 15 insertions, 4 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 45ead3d6235..da0fcda87a6 100644 --- a/db/post_migrate/20170518200835_rename_users_with_renamed_namespace.rb +++ b/db/post_migrate/20170518200835_rename_users_with_renamed_namespace.rb @@ -26,10 +26,21 @@ class RenameUsersWithRenamedNamespace < ActiveRecord::Migration def up 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}'" + users = Arel::Table.new(:users) + namespaces = Arel::Table.new(:namespaces) + predicate = namespaces[:owner_id].eq(users[:id]) + .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) end end |