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: 20211019152356_populate_pending_posts_count_column.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 PopulatePendingPostsCountColumn < ActiveRecord::Migration[6.1]
  d
    
  def up
    execute <<~SQL
      WITH to_update AS (
        SELECT COUNT(id) AS posts, created_by_id
        FROM reviewables
        WHERE type = 'ReviewableQueuedPost'
          AND status = #{ReviewableQueuedPost.statuses[:pending]}
        GROUP BY created_by_id
      )
      UPDATE user_stats
      SET pending_posts_count = to_update.posts
      FROM to_update
      WHERE to_update.created_by_id = user_stats.user_id
    SQL
  end