diff options
author | Bob Van Landuyt <bob@gitlab.com> | 2017-05-19 21:11:03 +0300 |
---|---|---|
committer | Bob Van Landuyt <bob@gitlab.com> | 2017-05-19 22:21:32 +0300 |
commit | 537b45b7fbe28efe529555a5a9ac25fad0cb7667 (patch) | |
tree | aadc0b4d288613b41f90ce89cf54f67172b59917 /db/post_migrate | |
parent | bc58f51d14aff86789dd5356245f1a8105aa8995 (diff) |
Rename users on mysql
Diffstat (limited to 'db/post_migrate')
-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 |