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: 20151016151834_add_root_folder_to_courses.rb
    path of file: ./repos/coursemology2/db/migrate
    
    the code of the file until where you have to start completion: # frozen_string_literal: true
class AddRootFolderToCourses < ActiveRecord::Migration[4.2]
  # Create root folders for existing courses
  def up
    all_courses = exec_query('SELECT * FROM courses')
    valid_course_ids = exec_query(
      'SELECT course_id
       FROM course_material_folders
       WHERE parent_id IS NULL'
    ).map { |r| r['course_id'] }

    invalid_courses = all_courses.select { |c| !valid_course_ids.include?(c['id']) }
    invalid_courses.each do |course|
      execute(
   
    
  def up
    all_courses = exec_query('SELECT * FROM courses')
    valid_course_ids = exec_query(
      'SELECT course_id
       FROM course_material_folders
       WHERE parent_id IS NULL'
    ).map { |r| r['course_id'] }

    invalid_courses = all_courses.select { |c| !valid_course_ids.include?(c['id']) }
    invalid_courses.each do |course|
      execute(
        "INSERT INTO course_material_folders
                     (course_id,
                      name,
                      start_at,
                      creator_id,
                      updater_id,
                      created_at,
                      updated_at)
         VALUES      (#{course['id']},
                      'Root',
                      '#{Time.zone.now.to_s(:db)}',
                      #{course['creator_id']},
                      #{course['updater_id']},
                      '#{Time.zone.now.to_s(:db)}',
                      '#{Time.zone.now.to_s(:db)}')"
      )
    end
  end