def ensure_user_exists(session, user_name, model):
    """
    Create a user in the database and return the user_id integer
    """
    user = session.query(model).filter(model.user_name.ilike(user_name)).first(
        )
    if not user:
        user = model(user_name=user_name)
        session.add(user)
        session.commit()
    return user.user_id
