code: def upgrade(
      config: Config,
      revision: str,
      sql: bool = False,
      tag: Optional[str] = None,
  ) -> None:
      """Upgrade to a later version.
  
      :param config: a :class:`.Config` instance.
  
      :param revision: string revision target or range for --sql mode
  
      :param sql: if True, use ``--sql`` mode
  
      :param tag: an arbitrary "tag" that can be intercepted by custom
       ``env.py`` scripts via the :meth:`.EnvironmentContext.get_tag_argument`
       method.
  
      """
  
      script = ScriptDirectory.from_config(config)
  
      starting_rev = None
      if ":" in revision:
          if not sql:
              raise util.CommandError("Range revision not allowed")
          starting_rev, revision = revision.split(":", 2)
  
      def upgrade(rev, context):
          return script._upgrade_revs(revision, rev)
  
      with EnvironmentContext(
          config,
          script,
          fn=upgrade,
          as_sql=sql,
          starting_rev=starting_rev,
          destination_rev=revision,
          tag=tag,
      ):
          script.run_env()
  
imports: from __future__ import annotations
  import os
  from typing import List
  from typing import Optional
  from typing import TYPE_CHECKING
  from typing import Union
  from .None import autogenerate
  from .None import util
  from .runtime.environment import EnvironmentContext
  from .script import ScriptDirectory
label_desc: Use image node_id 6 for calling a global function with example usage: upgrade(config, revision, sql, tag) and returns: script