You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: 20210215231312_fix_group_flair_avatar_upload_security_and_acls.rb
    path of file: ./repos/discourse/db/migrate
    
    the code of the file until where you have to start completion: # frozen_string_literal: true

class FixGroupFlairAvatarUploadSecurityAndAcls < ActiveRecord::Migration[6.0]
  disable_ddl_transaction!

  def up
    upload_ids = DB.query_single(<<~SQL)
      SELECT flair_upload_id
    
  def up
    upload_ids = DB.query_single(<<~SQL)
      SELECT flair_upload_id
      FROM groups
      WHERE flair_upload_id IS NOT NULL
     SQL

    if upload_ids.any?
      reason = "group_flair fixup migration"
      DB.exec(<<~SQL, upload_ids: upload_ids, reason: reason, now: Time.zone.now)
        UPDATE uploads SET secure = false, security_last_changed_at = :now, updated_at = :now, security_last_changed_reason = :reason
        WHERE id IN (:upload_ids) AND uploads.secure
      SQL

      if Discourse.store.external?
        uploads =
          Upload.where(id: upload_ids, secure: false).where("updated_at = security_last_changed_at")
        uploads.each do |upload|
          Discourse.store.update_upload_ACL(upload)
          upload.touch
        end
      end