code: def _downgrade_v7(op):
      tmp_name = "_new_equities"
      op.create_table(
          tmp_name,
          sa.Column(
              "sid",
              sa.Integer,
              unique=True,
              nullable=False,
              primary_key=True,
          ),
          sa.Column("asset_name", sa.Text),
          sa.Column(
              "start_date", sa.Integer, default=0, nullable=False
          ),
          sa.Column("end_date", sa.Integer, nullable=False),
          sa.Column("first_traded", sa.Integer),
          sa.Column("auto_close_date", sa.Integer),
          # remove foreign key to exchange
          sa.Column("exchange", sa.Text),
          # add back exchange full column
          sa.Column("exchange_full", sa.Text),
      )
      op.execute(
          """
          insert into
              _new_equities
          select
              eq.sid,
              eq.asset_name,
              eq.start_date,
              eq.end_date,
              eq.first_traded,
              eq.auto_close_date,
              ex.canonical_name,
              ex.exchange
          from
              equities eq
          inner join
              exchanges ex
          on
              eq.exchange == ex.exchange
          where
              ex.country_code in ('US', '??')
          """,
      )
      op.drop_table("equities")
      op.rename_table(tmp_name, "equities")
  
      # rebuild all tables without a foreign key to ``exchanges``
      alter_columns(
          op,
          "futures_root_symbols",
          sa.Column(
              "root_symbol",
              sa.Text,
              unique=True,
              nullable=False,
              primary_key=True,
          ),
          sa.Column("root_symbol_id", sa.Integer),
          sa.Column("sector", sa.Text),
          sa.Column("description", sa.Text),
          sa.Column("exchange", sa.Text),
      )
      alter_columns(
          op,
          "futures_contracts",
          sa.Column(
              "sid",
              sa.Integer,
              unique=True,
              nullable=False,
              primary_key=True,
          ),
          sa.Column("symbol", sa.Text, unique=True, index=True),
          sa.Column("root_symbol", sa.Text, index=True),
          sa.Column("asset_name", sa.Text),
          sa.Column(
              "start_date", sa.Integer, default=0, nullable=False
          ),
          sa.Column("end_date", sa.Integer, nullable=False),
          sa.Column("first_traded", sa.Integer),
          sa.Column("exchange", sa.Text),
          sa.Column("notice_date", sa.Integer, nullable=False),
          sa.Column("expiration_date", sa.Integer, nullable=False),
          sa.Column("auto_close_date", sa.Integer, nullable=False),
          sa.Column("multiplier", sa.Float),
          sa.Column("tick_size", sa.Float),
      )
  
      # drop the ``country_code`` and ``canonical_name`` columns
      alter_columns(
          op,
          "exchanges",
          sa.Column(
              "exchange",
              sa.Text,
              unique=True,
              nullable=False,
              primary_key=True,
          ),
          sa.Column("timezone", sa.Text),
          # Set the timezone to NULL because we don't know what it was before.
          # Nothing in zipline reads the timezone so it doesn't matter.
          selection_string="exchange, NULL",
      )
      op.rename_table("exchanges", "futures_exchanges")
  
      # add back the foreign keys that previously existed
      alter_columns(
          op,
          "futures_root_symbols",
          sa.Column(
              "root_symbol",
              sa.Text,
              unique=True,
              nullable=False,
              primary_key=True,
          ),
          sa.Column("root_symbol_id", sa.Integer),
          sa.Column("sector", sa.Text),
          sa.Column("description", sa.Text),
          sa.Column(
              "exchange",
              sa.Text,
              sa.ForeignKey("futures_exchanges.exchange"),
          ),
      )
      alter_columns(
          op,
          "futures_contracts",
          sa.Column(
              "sid",
              sa.Integer,
              unique=True,
              nullable=False,
              primary_key=True,
          ),
          sa.Column("symbol", sa.Text, unique=True, index=True),
          sa.Column(
              "root_symbol",
              sa.Text,
              sa.ForeignKey("futures_root_symbols.root_symbol"),
              index=True,
          ),
          sa.Column("asset_name", sa.Text),
          sa.Column(
              "start_date", sa.Integer, default=0, nullable=False
          ),
          sa.Column("end_date", sa.Integer, nullable=False),
          sa.Column("first_traded", sa.Integer),
          sa.Column(
              "exchange",
              sa.Text,
              sa.ForeignKey("futures_exchanges.exchange"),
          ),
          sa.Column("notice_date", sa.Integer, nullable=False),
          sa.Column("expiration_date", sa.Integer, nullable=False),
          sa.Column("auto_close_date", sa.Integer, nullable=False),
          sa.Column("multiplier", sa.Float),
          sa.Column("tick_size", sa.Float),
      )
  
      # Delete equity_symbol_mappings records that no longer refer to valid sids.
      op.execute(
          """
          DELETE FROM
              equity_symbol_mappings
          WHERE
              sid NOT IN (SELECT sid FROM equities);
          """
      )
  
      # Delete asset_router records that no longer refer to valid sids.
      op.execute(
          """
          DELETE FROM
              asset_router
          WHERE
              sid
              NOT IN (
                  SELECT sid FROM equities
                  UNION
                  SELECT sid FROM futures_contracts
              );
          """
      )
  
imports: from alembic.migration import MigrationContext
  from alembic.operations import Operations
  import sqlalchemy
  from toolz.curried import do, operator
  from zipline.assets.asset_writer import write_version_info
  from zipline.utils.compat import wraps
  from zipline.errors import AssetDBImpossibleDowngrade
  from zipline.utils.preprocess import preprocess
  from zipline.utils.sqlite_utils import coerce_string_to_eng
label_desc: Use image node_id 11 for calling a global function with example usage: _downgrade_v7(op) without return types