blob: b2cf8298e4f9dbdc95288e8bc49fe2728bde1d86 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# frozen_string_literal: true
module Gitlab
module BackgroundMigration
# This class is used to update the delayed_project_removal column
# for user namespaces of the namespace_settings table.
class UpdateDelayedProjectRemovalToNullForUserNamespaces < Gitlab::BackgroundMigration::BatchedMigrationJob
# Migration only version of `namespace_settings` table
class NamespaceSetting < ::ApplicationRecord
self.table_name = 'namespace_settings'
end
operation_name :set_delayed_project_removal_to_null_for_user_namespace
def perform
each_sub_batch do |sub_batch|
set_delayed_project_removal_to_null_for_user_namespace(sub_batch)
end
end
private
def set_delayed_project_removal_to_null_for_user_namespace(relation)
NamespaceSetting.connection.execute(
<<~SQL
UPDATE namespace_settings
SET delayed_project_removal = NULL
WHERE
namespace_settings.namespace_id IN (
SELECT
namespace_settings.namespace_id
FROM
namespace_settings
INNER JOIN namespaces ON namespaces.id = namespace_settings.namespace_id
WHERE
namespaces.id IN (#{relation.select(:namespace_id).to_sql})
AND namespaces.type = 'User'
AND namespace_settings.delayed_project_removal = FALSE)
SQL
)
end
end
end
end
|