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!
2 files
+ 10
10
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -26,15 +26,12 @@ class RenameUsersWithRenamedNamespace < ActiveRecord::Migration
@@ -26,15 +26,12 @@ class RenameUsersWithRenamedNamespace < ActiveRecord::Migration
]
]
def up
def up
namespace_table = Arel::Table.new('namespaces')
DISALLOWED_ROOT_PATHS.each do |path|
users_table = Arel::Table.new('users')
update_sql = "UPDATE users SET username = namespaces.path "\
matching_path = namespace_table.project(namespace_table[:path])
"FROM namespaces WHERE namespaces.owner_id = users.id "\
.join(users_table).on(users_table[:id].eq(namespace_table[:owner_id]))
"AND namespaces.type IS NULL "\
.where(users_table[:username].not_eq(namespace_table[:path]))
"AND users.username ILIKE '#{path}'"
path_name = Arel::Nodes::SqlLiteral.new("matching_path.path FROM (#{matching_path.to_sql}) as matching_path")
connection.execute(update_sql)
update_column_in_batches(:users, :username, path_name) do |table, query|
query.where(table[:username].matches_any(DISALLOWED_ROOT_PATHS))
end
end
end
end
Loading