code: def downgrade(engine, desired_version):
      """Downgrades the assets db at the given engine to the desired version.
  
      Parameters
      ----------
      engine : Engine
          An SQLAlchemy engine to the assets database.
      desired_version : int
          The desired resulting version for the assets database.
      """
  
      # Check the version of the db at the engine
      with engine.begin() as conn:
          metadata = sa.MetaData(conn)
          metadata.reflect()
          version_info_table = metadata.tables["version_info"]
          starting_version = sa.select(
              (version_info_table.c.version,)
          ).scalar()
  
          # Check for accidental upgrade
          if starting_version < desired_version:
              raise AssetDBImpossibleDowngrade(
                  db_version=starting_version,
                  desired_version=desired_version,
              )
  
          # Check if the desired version is already the db version
          if starting_version == desired_version:
              # No downgrade needed
              return
  
          # Create alembic context
          ctx = MigrationContext.configure(conn)
          op = Operations(ctx)
  
          # Integer keys of downgrades to run
          # E.g.: [5, 4, 3, 2] would downgrade v6 to v2
          downgrade_keys = range(desired_version, starting_version)[
              ::-1
          ]
  
          # Disable foreign keys until all downgrades are complete
          _pragma_foreign_keys(conn, False)
  
          # Execute the downgrades in order
          for downgrade_key in downgrade_keys:
              _downgrade_methods[downgrade_key](
                  op, conn, version_info_table
              )
  
          # Re-enable foreign keys
          _pragma_foreign_keys(conn, True)
  
file_path: catalyst/catalyst/assets/asset_db_migrations.py
imports: from functools import wraps
  from alembic.migration import MigrationContext
  from alembic.operations import Operations
  import sqlalchemy
  from toolz.curried import do, operator
  from catalyst.assets.asset_writer import write_version_info
  from catalyst.errors import AssetDBImpossibleDowngrade
  from catalyst.utils.preprocess import preprocess
  from catalyst.utils.sqlite_utils import coerce_string_to_eng
label_desc: Use image node_id 1 for calling a global function with example usage: downgrade(engine, desired_version) without return types