Migrated sqlalchemy to sql