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: 20130213184141_change_permalink_to_not_null.rb
    path of file: ./repos/catarse/db/migrate
    
    the code of the file until where you have to start completion: # encoding: utf-8
#
class ChangePermalinkToNotNull < ActiveRecord::Migration
  def up
    execute <<-SQL
    UPDATE projects SET permalink = regexp_replace(unaccent(lower(trim(name))), '[^\\w]|[ªº]', '-', 'gi') 
    WHERE NU
    
  def up
    execute <<-SQL
    UPDATE projects SET permalink = regexp_replace(unaccent(lower(trim(name))), '[^\\w]|[ªº]', '-', 'gi') 
    WHERE NULLIF(trim(permalink), '') is NULL AND (SELECT count(*) < 2 FROM projects p2 
      WHERE regexp_replace(unaccent(lower(trim(p2.name))), '[^\\w]|[ªº]', '-', 'gi') = regexp_replace(unaccent(lower(trim(projects.name))), '[^\\w]|[ªº]', '-', 'gi'));
    UPDATE projects SET permalink = projects.id::text || '-' || regexp_replace(unaccent(lower(trim(name))), '[^\\w]|[ªº]', '-', 'gi') WHERE NULLIF(trim(permalink), '') is NULL;
    SQL
    change_column :projects, :permalink, :text, null: false
  end