prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Set plugin migration version in between each migration
  https://github.com/CTFd/CTFd/blob/e1991e16963b10302baa7cc50d52071a5053bf2f/CTFd/plugins/migrations.py#L72-L77
  
  This code here probably should be setting the plugin version in between each migration so that if a migration fails it doesn't need to be started from the beginning again. 
  
  </issue>
  <code>
  [start of CTFd/plugins/migrations.py]
  1 import inspect
  2 import os
  3 
  4 from alembic.config import Config
  5 from alembic.migration import MigrationContext
  6 from alembic.operations import Operations
  7 from alembic.script import ScriptDirectory
  8 from flask import current_app
  9 from sqlalchemy import create_engine, pool
  10 
  11 from CTFd.utils import get_config, set_config
  12 
  13 
  14 def current(plugin_name=None):
  15     if plugin_name is None:
  16         # Get the directory name of the plugin if unspecified
  17         # Doing it this way doesn't waste the rest of the inspect.stack call
  18         frame = inspect.currentframe()
  19         caller_info = inspect.getframeinfo(frame.f_back)
  20         caller_path = caller_info[0]
  21         plugin_name = os.path.basename(os.path.dirname(caller_path))
  22 
  23     return get_config(plugin_name + "_alembic_version")
  24 
  25 
  26 def upgrade(plugin_name=None, revision=None, lower="current"):
  27     database_url = current_app.config.get("SQLALCHEMY_DATABASE_URI")
  28     if database_url.startswith("sqlite"):
  29         current_app.db.create_all()
  30         return
  31 
  32     if plugin_name is None:
  33         # Get the directory name of the plugin if unspecified
  34         # Doing it this way doesn't waste the rest of the inspect.stack call
  35         frame = inspect.currentframe()
  36         caller_info = inspect.getframeinfo(frame.f_back)
  37         caller_path = caller_info[0]
  38         plugin_name = os.path.basename(os.path.dirname(caller_path))
  39 
  40     # Check if the plugin has migraitons
  41     migrations_path = os.path.join(current_app.plugins_dir, plugin_name, "migrations")
  42     if os.path.isdir(migrations_path) is False:
  43         return
  44 
  45     engine = create_engine(database_url, poolclass=pool.NullPool)
  46     conn = engine.connect()
  47     context = MigrationContext.configure(conn)
  48     op = Operations(context)
  49 
  50     # Find the list of migrations to run
  51     config = Config()
  52     config.set_main_option("script_location", migrations_path)
  53     config.set_main_option("version_locations", migrations_path)
  54     script = ScriptDirectory.from_config(config)
  55 
  56     # Choose base revision for plugin upgrade
  57     # "current" points to the current plugin version stored in config
  58     # None represents the absolute base layer (e.g. first installation)
  59     if lower == "current":
  60         lower = get_config(plugin_name + "_alembic_version")
  61 
  62     # Do we upgrade to head or to a specific revision
  63     if revision is None:
  64         upper = script.get_current_head()
  65     else:
  66         upper = revision
  67 
  68     # Apply from lower to upper
  69     revs = list(script.iterate_revisions(lower=lower, upper=upper))
  70     revs.reverse()
  71 
  72     try:
  73         for r in revs:
  74             with context.begin_transaction():
  75                 r.module.upgrade(op=op)
  76     finally:
  77         conn.close()
  78 
  79     # Set the new latest revision
  80     set_config(plugin_name + "_alembic_version", upper)
  81
  [end of CTFd/plugins/migrations.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/CTFd/plugins/migrations.py b/CTFd/plugins/migrations.py
  --- a/CTFd/plugins/migrations.py
  +++ b/CTFd/plugins/migrations.py
  @@ -73,6 +73,9 @@
           for r in revs:
               with context.begin_transaction():
                   r.module.upgrade(op=op)
  +            # Set revision that succeeded so we don't need
  +            # to start from the beginning on failure
  +            set_config(plugin_name + "_alembic_version", r.revision)
       finally:
           conn.close()
  
verification_info: {"golden_diff": "diff --git a/CTFd/plugins/migrations.py b/CTFd/plugins/migrations.py\n--- a/CTFd/plugins/migrations.py\n+++ b/CTFd/plugins/migrations.py\n@@ -73,6 +73,9 @@\n         for r in revs:\n             with context.begin_transaction():\n                 r.module.upgrade(op=op)\n+            # Set revision that succeeded so we don't need\n+            # to start from the beginning on failure\n+            set_config(plugin_name + \"_alembic_version\", r.revision)\n     finally:\n         conn.close()\n", "issue": "Set plugin migration version in between each migration\nhttps://github.com/CTFd/CTFd/blob/e1991e16963b10302baa7cc50d52071a5053bf2f/CTFd/plugins/migrations.py#L72-L77\r\n\r\nThis code here probably should be setting the plugin version in between each migration so that if a migration fails it doesn't need to be started from the beginning again. \n", "before_files": [{"content": "import inspect\nimport os\n\nfrom alembic.config import Config\nfrom alembic.migration import MigrationContext\nfrom alembic.operations import Operations\nfrom alembic.script import ScriptDirectory\nfrom flask import current_app\nfrom sqlalchemy import create_engine, pool\n\nfrom CTFd.utils import get_config, set_config\n\n\ndef current(plugin_name=None):\n    if plugin_name is None:\n        # Get the directory name of the plugin if unspecified\n        # Doing it this way doesn't waste the rest of the inspect.stack call\n        frame = inspect.currentframe()\n        caller_info = inspect.getframeinfo(frame.f_back)\n        caller_path = caller_info[0]\n        plugin_name = os.path.basename(os.path.dirname(caller_path))\n\n    return get_config(plugin_name + \"_alembic_version\")\n\n\ndef upgrade(plugin_name=None, revision=None, lower=\"current\"):\n    database_url = current_app.config.get(\"SQLALCHEMY_DATABASE_URI\")\n    if database_url.startswith(\"sqlite\"):\n        current_app.db.create_all()\n        return\n\n    if plugin_name is None:\n        # Get the directory name of the plugin if unspecified\n        # Doing it this way doesn't waste the rest of the inspect.stack call\n        frame = inspect.currentframe()\n        caller_info = inspect.getframeinfo(frame.f_back)\n        caller_path = caller_info[0]\n        plugin_name = os.path.basename(os.path.dirname(caller_path))\n\n    # Check if the plugin has migraitons\n    migrations_path = os.path.join(current_app.plugins_dir, plugin_name, \"migrations\")\n    if os.path.isdir(migrations_path) is False:\n        return\n\n    engine = create_engine(database_url, poolclass=pool.NullPool)\n    conn = engine.connect()\n    context = MigrationContext.configure(conn)\n    op = Operations(context)\n\n    # Find the list of migrations to run\n    config = Config()\n    config.set_main_option(\"script_location\", migrations_path)\n    config.set_main_option(\"version_locations\", migrations_path)\n    script = ScriptDirectory.from_config(config)\n\n    # Choose base revision for plugin upgrade\n    # \"current\" points to the current plugin version stored in config\n    # None represents the absolute base layer (e.g. first installation)\n    if lower == \"current\":\n        lower = get_config(plugin_name + \"_alembic_version\")\n\n    # Do we upgrade to head or to a specific revision\n    if revision is None:\n        upper = script.get_current_head()\n    else:\n        upper = revision\n\n    # Apply from lower to upper\n    revs = list(script.iterate_revisions(lower=lower, upper=upper))\n    revs.reverse()\n\n    try:\n        for r in revs:\n            with context.begin_transaction():\n                r.module.upgrade(op=op)\n    finally:\n        conn.close()\n\n    # Set the new latest revision\n    set_config(plugin_name + \"_alembic_version\", upper)\n", "path": "CTFd/plugins/migrations.py"}]}