def generate_old_db(env_dir, hub_version, db_url):
    """Generate an old jupyterhub database

    Installs a particular jupyterhub version in a virtualenv
    and runs populate_db.py to populate a database
    """
    env_pip = os.path.join(env_dir, 'bin', 'pip')
    env_py = os.path.join(env_dir, 'bin', 'python')
    check_call([sys.executable, '-m', 'virtualenv', env_dir])
    pkgs = ['jupyterhub==' + hub_version]

    # older jupyterhub needs older sqlachemy version
    if V(hub_version) < V("2"):
        pkgs.append('sqlalchemy<1.4')
    elif V(hub_version) < V("3.1.1"):
        pkgs.append('sqlalchemy<2')

    if 'mysql' in db_url:
        pkgs.append('mysqlclient')
    elif 'postgres' in db_url:
        pkgs.append('psycopg2-binary')
    check_call([env_pip, 'install'] + pkgs)
    check_call([env_py, populate_db, db_url])
Generate an old jupyterhub database

Installs a particular jupyterhub version in a virtualenv
and runs populate_db.py to populate a database
jupyterhub/tests/test_db.py