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: 20170905095543_add_latest_post_at_to_course_forum_topic.rb
    path of file: ./repos/coursemology2/db/migrate
    
    the code of the file until where you have to start completion: class AddLatestPostAtToCourseForumTopic < ActiveRecord::Migration[4.2]
  def change
    add_column :course_forum_topics, :latest_post_at, :datetime

    exec_query(<<-SQL)
      UPDATE course_forum_topics
      SET latest_post_at = created_at
    SQL

    exec_query(<<-SQL)
      UPDATE course_forum_topics AS cft
      SET latest_post_at = t2.latest_post_at
      FROM (
        SELECT cdt.actable_id AS id, t1.latest_post_at AS latest_post_at FROM (
          (
            SELECT topic_id, MAX(created_at) AS latest_post_at
            FROM course_discussion_posts
            GROUP BY top
    
  def change
    add_column :course_forum_topics, :latest_post_at, :datetime

    exec_query(<<-SQL)
      UPDATE course_forum_topics
      SET latest_post_at = created_at
    SQL

    exec_query(<<-SQL)
      UPDATE course_forum_topics AS cft
      SET latest_post_at = t2.latest_post_at
      FROM (
        SELECT cdt.actable_id AS id, t1.latest_post_at AS latest_post_at FROM (
          (
            SELECT topic_id, MAX(created_at) AS latest_post_at
            FROM course_discussion_posts
            GROUP BY topic_id
          ) AS t1
          JOIN course_discussion_topics AS cdt
          ON cdt.id = t1.topic_id
          AND cdt.actable_type = 'Course::Forum::Topic'
        )
      ) AS t2
      WHERE cft.id = t2.id
    SQL

    change_column_null :course_forum_topics, :latest_post_at, false
  end