Fixed get_next_spin_spec to work with postgres db