2022-07-23 23:45:48 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
namespace :gitlab do
|
|
|
|
namespace :db do
|
|
|
|
desc "GitLab | DB | Install prevent write triggers on all databases"
|
|
|
|
task lock_writes: [:environment, 'gitlab:db:validate_config'] do
|
2022-08-27 11:52:29 +05:30
|
|
|
Gitlab::Database::EachDatabase.each_database_connection(include_shared: false) do |connection, database_name|
|
2022-07-23 23:45:48 +05:30
|
|
|
schemas_for_connection = Gitlab::Database.gitlab_schemas_for_connection(connection)
|
2023-03-04 22:38:38 +05:30
|
|
|
|
|
|
|
Gitlab::Database::LockWritesManager.tables_to_lock(connection) do |table_name, schema_name|
|
2022-08-13 15:12:31 +05:30
|
|
|
# TODO: https://gitlab.com/gitlab-org/gitlab/-/issues/366834
|
|
|
|
next if schema_name == :gitlab_geo
|
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
lock_writes_manager = Gitlab::Database::LockWritesManager.new(
|
|
|
|
table_name: table_name,
|
|
|
|
connection: connection,
|
|
|
|
database_name: database_name,
|
2023-03-17 16:20:25 +05:30
|
|
|
with_retries: true,
|
2022-11-25 23:54:43 +05:30
|
|
|
logger: Logger.new($stdout),
|
|
|
|
dry_run: ENV['DRY_RUN'] == 'true'
|
2022-08-27 11:52:29 +05:30
|
|
|
)
|
|
|
|
|
2022-07-23 23:45:48 +05:30
|
|
|
if schemas_for_connection.include?(schema_name.to_sym)
|
2022-08-27 11:52:29 +05:30
|
|
|
lock_writes_manager.unlock_writes
|
2022-07-23 23:45:48 +05:30
|
|
|
else
|
2022-08-27 11:52:29 +05:30
|
|
|
lock_writes_manager.lock_writes
|
2022-07-23 23:45:48 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
desc "GitLab | DB | Remove all triggers that prevents writes from all databases"
|
|
|
|
task unlock_writes: :environment do
|
|
|
|
Gitlab::Database::EachDatabase.each_database_connection do |connection, database_name|
|
2023-03-04 22:38:38 +05:30
|
|
|
Gitlab::Database::LockWritesManager.tables_to_lock(connection) do |table_name, schema_name|
|
2022-08-13 15:12:31 +05:30
|
|
|
# TODO: https://gitlab.com/gitlab-org/gitlab/-/issues/366834
|
|
|
|
next if schema_name == :gitlab_geo
|
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
lock_writes_manager = Gitlab::Database::LockWritesManager.new(
|
|
|
|
table_name: table_name,
|
|
|
|
connection: connection,
|
|
|
|
database_name: database_name,
|
2023-03-17 16:20:25 +05:30
|
|
|
with_retries: true,
|
2022-08-27 11:52:29 +05:30
|
|
|
logger: Logger.new($stdout)
|
|
|
|
)
|
2022-07-23 23:45:48 +05:30
|
|
|
|
2022-08-27 11:52:29 +05:30
|
|
|
lock_writes_manager.unlock_writes
|
2022-07-23 23:45:48 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|