summaryrefslogtreecommitdiff
path: root/lib/gitlab/background_migration/backfill_project_settings.rb
blob: 7d7f19e1fdaaec7bad29259f74731ee547b09c3b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# frozen_string_literal: true

module Gitlab
  module BackgroundMigration
    # Backfill project_settings for a range of projects
    class BackfillProjectSettings
      def perform(start_id, end_id)
        ActiveRecord::Base.connection.execute <<~SQL
          INSERT INTO project_settings (project_id, created_at, updated_at)
            SELECT projects.id, now(), now()
            FROM projects
            WHERE projects.id BETWEEN #{start_id} AND #{end_id}
          ON CONFLICT (project_id) DO NOTHING;
        SQL
      end
    end
  end
end