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: 20191111153306_make_playlist_permalinks_unique_within_scope.rb
    path of file: ./repos/alonetone/db/migrate
    
    the code of the file until where you have to start completion: # frozen_string_literal: true

require 'slug'

class Playlist < ActiveRecord::Base
end

class MakePlaylistPermalinksUniqueWithinScope < ActiveRecord::Migration[6.0]
  def up
    Playlist.find_each do |playlist|
      playlist.reload

      duplicates = Playlist
                   .where(permalink: playlist.permalink)
                   .where(user_id: playlist.user_id)
                   .where.not(id: pl
    
  def up
    Playlist.find_each do |playlist|
      playlist.reload

      duplicates = Playlist
                   .where(permalink: playlist.permalink)
                   .where(user_id: playlist.user_id)
                   .where.not(id: playlist.id)
                   .order(id: :asc).to_a
      next if duplicates.empty?

      slug = Slug.generate(playlist.title)
      duplicates.each do |duplicate|
        slug = Slug.increment(slug)
        duplicate.update_column(:permalink, slug)
      end
    end
  end