def METHOD_NAME(table_name):
    """A context manager that drops indexes and constraints on the
    specified table, yields, then recreates them.
    According to postgres documentation, when doing bulk loads, this
    should be faster than having the indexes update during the insert.
    See https://www.postgresql.org/docs/current/static/populate.html
    for more.
    """
    with db.connection.cursor() as cursor:
        # Record index and constraint definitions
        indexes = {}
        constraints = {}
        cluster = None
        # Build lists of current constraints and indexes, and any
        # existing cluster
        cursor.execute(
            "SELECT conname, pg_get_constraintdef(c.oid) "
            "FROM pg_constraint c "
            "JOIN pg_namespace n "
            "ON n.oid = c.connamespace "
            "WHERE contype IN ('f', 'p','c','u') "
            "AND conrelid = '%s'::regclass "
            "ORDER BY contype;" % table_name
        )
        for name, definition in cursor.fetchall():
            constraints[name] = definition
        cursor.execute(
            "SELECT indexname, indexdef "
            "FROM pg_indexes "
            "WHERE tablename = '%s';" % table_name
        )
        for name, definition in cursor.fetchall():
            if name not in constraints.keys():
                # UNIQUE constraints actuall create indexes, so
                # we mustn't attempt to handle them twice
                indexes[name] = definition
        cursor.execute(
            """
            SELECT
              i.relname AS index_for_cluster
            FROM
              pg_index AS idx
            JOIN
              pg_class AS i
            ON
              i.oid = idx.indexrelid
            WHERE
              idx.indisclustered
              AND idx.indrelid::regclass = '%s'::regclass;
        """
            % table_name
        )
        row = cursor.fetchone()
        if row:
            cluster = row[0]
        # drop foreign key constraints
        for name in constraints.keys():
            cursor.execute("ALTER TABLE %s DROP CONSTRAINT %s" % (table_name, name))
        # drop indexes
        logger.info("Dropping indexes")
        for name in indexes.keys():
            cursor.execute("DROP INDEX %s" % name)
            logger.info("Dropped index %s" % name)
        logger.info("Running wrapped command")
        try:
            yield
        finally:
            # we're updating everything. This takes 52 minutes.
            # restore indexes
            print("Recreating indexes, don't hit Control-C!")
            logger.info("Recreating indexes")
            for name, cmd in indexes.items():
                cursor.execute(cmd)
                logger.info("Recreated index %s" % name)
            logger.info("Recreating constraints")
            # restore foreign key constraints
            for name, cmd in constraints.items():
                cmd = "ALTER TABLE %s " "ADD CONSTRAINT %s %s" % (table_name, name, cmd)
                cursor.execute(cmd)
                logger.info("Recreated constraint %s" % name)
            if cluster:
                cursor.execute("CLUSTER %s USING %s" % (table_name, cluster))
                cursor.execute("ANALYZE %s" % table_name)
                logger.info("CLUSTERED %s" % table_name)