qcodes/dataset/sqlite/db_upgrades/__init__.py
def upgrader(func: TUpgraderFunction) -> TUpgraderFunction:
    """
    Decorator for database version upgrade functions. An upgrade function
    must have the name `perform_db_upgrade_N_to_M` where N = M-1. For
    simplicity, an upgrade function must take a single argument of type
    `ConnectionPlus`. The upgrade function must either perform the upgrade
    and return (no return values allowed) or fail to perform the upgrade,
    in which case it must raise a RuntimeError. A failed upgrade must be
    completely rolled back before the RuntimeError is raises.

    The decorator takes care of logging about the upgrade and managing the
    database versioning.
    """
    name_comps = func.__name__.split('_')
    if not len(name_comps) == 6:
        raise NameError('Decorated function not a valid upgrader. '
                        'Must have name "perform_db_upgrade_N_to_M"')
    if not ''.join(name_comps[:3]+[name_comps[4]]) == 'performdbupgradeto':
        raise NameError('Decorated function not a valid upgrader. '
                        'Must have name "perform_db_upgrade_N_to_M"')
    from_version = int(name_comps[3])
    to_version = int(name_comps[5])

    if not to_version == from_version+1:
        raise ValueError(f'Invalid upgrade versions in function name: '
                         f'{func.__name__}; upgrade from version '
                         f'{from_version} to version {to_version}.'
                         ' Can only upgrade from version N'
                         ' to version N+1')

    @wraps(func)
    def do_upgrade(conn: ConnectionPlus) -> None:

        log.info(f'Starting database upgrade version {from_version} '
                 f'to {to_version}')

        start_version = get_user_version(conn)
        if start_version != from_version:
            log.info(f'Skipping upgrade {from_version} -> {to_version} as'
                     f' current database version is {start_version}.')
            return

        # This function either raises or returns
        func(conn)

        set_user_version(conn, to_version)
        log.info(f'Succesfully performed upgrade {from_version} '
                 f'-> {to_version}')

    _UPGRADE_ACTIONS[to_version] = do_upgrade

    return do_upgrade

    Decorator for database version upgrade functions. An upgrade function
    must have the name `perform_db_upgrade_N_to_M` where N = M-1. For
    simplicity, an upgrade function must take a single argument of type
    `ConnectionPlus`. The upgrade function must either perform the upgrade
    and return (no return values allowed) or fail to perform the upgrade,
    in which case it must raise a RuntimeError. A failed upgrade must be
    completely rolled back before the RuntimeError is raises.

    The decorator takes care of logging about the upgrade and managing the
    database versioning.
    
Decorator for database version upgrade functions. An upgrade function
must have the name `perform_db_upgrade_N_to_M` where N = M-1. For
simplicity, an upgrade function must take a single argument of type
`ConnectionPlus`. The upgrade function must either perform the upgrade
and return (no return values allowed) or fail to perform the upgrade,
in which case it must raise a RuntimeError. A failed upgrade must be
completely rolled back before the RuntimeError is raises.

The decorator takes care of logging about the upgrade and managing the
database versioning.
Decorator for database version upgrade functions . An upgrade function must have the name ` perform_db_upgrade_N_to_M ` where N = M - 1 . For simplicity an upgrade function must take a single argument of type ` ConnectionPlus ` . The upgrade function must either perform the upgrade and return ( no return values allowed ) or fail to perform the upgrade in which case it must raise a RuntimeError . A failed upgrade must be completely rolled back before the RuntimeError is raises . The decorator takes care of logging about the upgrade and managing the database versioning .
def upgrader(func: TUpgraderFunction) -> TUpgraderFunction:
    name_comps = func.__name__.split('_')
    if not len(name_comps) == 6:
        raise NameError('Decorated function not a valid upgrader. '
                        'Must have name "perform_db_upgrade_N_to_M"')
    if not ''.join(name_comps[:3]+[name_comps[4]]) == 'performdbupgradeto':
        raise NameError('Decorated function not a valid upgrader. '
                        'Must have name "perform_db_upgrade_N_to_M"')
    from_version = int(name_comps[3])
    to_version = int(name_comps[5])
    if not to_version == from_version+1:
        raise ValueError(f'Invalid upgrade versions in function name: '
                         f'{func.__name__}; upgrade from version '
                         f'{from_version} to version {to_version}.'
                         ' Can only upgrade from version N'
                         ' to version N+1')
    @wraps(func)
    def do_upgrade(conn: ConnectionPlus) -> None:
        log.info(f'Starting database upgrade version {from_version} '
                 f'to {to_version}')
        start_version = get_user_version(conn)
        if start_version != from_version:
            log.info(f'Skipping upgrade {from_version} -> {to_version} as'
                     f' current database version is {start_version}.')
            return
        func(conn)
        set_user_version(conn, to_version)
        log.info(f'Succesfully performed upgrade {from_version} '
                 f'-> {to_version}')
    _UPGRADE_ACTIONS[to_version] = do_upgrade
    return do_upgrade
def upgrader ( func : TUpgraderFunction ) -> TUpgraderFunction : name_comps = func . __name__ . split ( '_' ) if not len ( name_comps ) == 6 : raise NameError ( 'Decorated function not a valid upgrader. ' 'Must have name "perform_db_upgrade_N_to_M"' ) if not '' . join ( name_comps [ : 3 ] + [ name_comps [ 4 ] ] ) == 'performdbupgradeto' : raise NameError ( 'Decorated function not a valid upgrader. ' 'Must have name "perform_db_upgrade_N_to_M"' ) from_version = int ( name_comps [ 3 ] ) to_version = int ( name_comps [ 5 ] ) if not to_version == from_version + 1 : raise ValueError ( f'Invalid upgrade versions in function name: ' f'{func.__name__}; upgrade from version ' f'{from_version} to version {to_version}.' ' Can only upgrade from version N' ' to version N+1' ) @ wraps ( func ) def do_upgrade ( conn : ConnectionPlus ) -> None : log . info ( f'Starting database upgrade version {from_version} ' f'to {to_version}' ) start_version = get_user_version ( conn ) if start_version != from_version : log . info ( f'Skipping upgrade {from_version} -> {to_version} as' f' current database version is {start_version}.' ) return func ( conn ) set_user_version ( conn , to_version ) log . info ( f'Succesfully performed upgrade {from_version} ' f'-> {to_version}' ) _UPGRADE_ACTIONS [ to_version ] = do_upgrade return do_upgrade
Decorator for database version upgrade functions.
Decorator for database version upgrade functions .
"""
    Decorator for database version upgrade functions. An upgrade function
    must have the name `perform_db_upgrade_N_to_M` where N = M-1. For
    simplicity, an upgrade function must take a single argument of type
    `ConnectionPlus`. The upgrade function must either perform the upgrade
    and return (no return values allowed) or fail to perform the upgrade,
    in which case it must raise a RuntimeError. A failed upgrade must be
    completely rolled back before the RuntimeError is raises.

    The decorator takes care of logging about the upgrade and managing the
    database versioning.
    """ # This function either raises or returns
func
TUpgraderFunction