Skip to content
Snippets Groups Projects

Fix incorrect renaming migrations

Merged Bob Van Landuyt :neckbeard: requested to merge bvl-fix-already-renamed-paths into master
All threads resolved!
1 file
+ 15
4
Compare changes
  • Side-by-side
  • Inline
@@ -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
Loading