Class: Gitlab::BackgroundMigration::MigratePagesMetadata

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/background_migration/migrate_pages_metadata.rb

Overview

Class that will insert record into project_pages_metadata for each existing project

Instance Method Summary collapse

Instance Method Details

#perform(start_id, stop_id) ⇒ Object


8
9
10
# File 'lib/gitlab/background_migration/migrate_pages_metadata.rb', line 8

def perform(start_id, stop_id)
  perform_on_relation(Project.where(id: start_id..stop_id))
end

#perform_on_relation(relation) ⇒ Object


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/gitlab/background_migration/migrate_pages_metadata.rb', line 12

def perform_on_relation(relation)
  successful_pages_deploy = <<~SQL
    SELECT TRUE
    FROM ci_builds
    WHERE ci_builds.type = 'GenericCommitStatus'
      AND ci_builds.status = 'success'
      AND ci_builds.stage = 'deploy'
      AND ci_builds.name = 'pages:deploy'
      AND ci_builds.project_id = projects.id
    LIMIT 1
  SQL

  select_from = relation
    .select("projects.id", "COALESCE((#{successful_pages_deploy}), FALSE)")
    .to_sql

  ActiveRecord::Base.connection_pool.with_connection do |connection|
    connection.execute <<~SQL
      INSERT INTO project_pages_metadata (project_id, deployed)
    #{select_from}
      ON CONFLICT (project_id) DO NOTHING
    SQL
  end
end