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: 20170110124012_add_inactive_email_function.rb
    path of file: ./repos/catarse/db/migrate
    
    the code of the file until where you have to start completion: class AddInactiveEmailFunction <
    
  def change
    execute <<-SQL
    CREATE INDEX sendgrid_events_notification_user_idx ON sendgrid_events USING btree (notification_user);

    CREATE OR REPLACE FUNCTION email_active(users) RETURNS boolean
    LANGUAGE sql STABLE SECURITY DEFINER
    AS $_$
      SELECT EXISTS (SELECT true from sendgrid_events 
        WHERE event IN ('open', 'click') and notification_user = $1.id and created_at > (current_timestamp - '1 month'::interval));
    $_$;
    SQL

  end