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: 20230712064637_replace_old_fk_p_ci_builds_metadata_to_builds_v2.rb
    path of file: ./repos/gitlabhq/db/post_migrate
    
    the code of the file until where you have to start completion: # frozen_string_literal: true

class ReplaceOldFkPCiBuildsMetadataToBuildsV2 < Gitlab::Database::Migration[2.1]
  include Gitlab::Database::PartitioningMigrationHelpers
  include Gitlab::Database::MigrationHelpers::WraparoundAutovacuum

  disable_ddl_transaction!

  def up
    return unless should_run?
    return if n
    
  def up
    return unless should_run?
    return if new_foreign_key_exists?

    with_lock_retries do
      remove_foreign_key_if_exists :p_ci_builds_metadata, :ci_builds,
        name: :fk_e20479742e_p, reverse_lock_order: true

      rename_constraint :p_ci_builds_metadata, :temp_fk_e20479742e_p, :fk_e20479742e_p

      Gitlab::Database::PostgresPartitionedTable.each_partition(:p_ci_builds_metadata) do |partition|
        rename_constraint partition.identifier, :temp_fk_e20479742e_p, :fk_e20479742e_p
      end
    end
  end