Welcome to mirror list, hosted at ThFree Co, Russian Federation.

backfill_project_updated_at_after_repository_storage_move.rb « background_migration « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 61eb3b332de754c75713987158fb154fda1a63e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# frozen_string_literal: true

module Gitlab
  module BackgroundMigration
    # Update existent project update_at column after their repository storage was moved
    class BackfillProjectUpdatedAtAfterRepositoryStorageMove
      def perform(*project_ids)
        updated_repository_storages = ProjectRepositoryStorageMove.select("project_id, MAX(updated_at) as updated_at").where(project_id: project_ids).group(:project_id)

        Project.connection.execute <<-SQL
          WITH repository_storage_cte as (
            #{updated_repository_storages.to_sql}
          )
          UPDATE projects
          SET updated_at = (repository_storage_cte.updated_at + interval '1 second')
          FROM repository_storage_cte
          WHERE projects.id = repository_storage_cte.project_id AND projects.updated_at <= repository_storage_cte.updated_at
        SQL
      end
    end
  end
end