def upgrade():
    op.add_column('users', sa.Column('created', sa.DateTime, nullable=True))
    c = op.get_bind()
    # fill created date with current time
    now = utcnow()
    c.execute(
        f"""
        UPDATE users
        SET created='{now}'
        """
    )

    tables = sa.inspect(c.engine).get_table_names()

    if 'spawners' in tables:
        op.add_column('spawners', sa.Column('started', sa.DateTime, nullable=True))
        # fill started value with now for running servers
        c.execute(
            f"""
            UPDATE spawners
            SET started='{now}'
            WHERE server_id IS NOT NULL
            """
        )
)

tables = sa.inspect(c.engine).get_table_names()

if 'spawners' in tables:
op.add_column('spawners', sa.Column('started', sa.DateTime, nullable=True))
# fill started value with now for running servers
c.execute(
f
jupyterhub/alembic/versions/99a28a4418e1_user_created.py