From cfab0475f33233a4d36d729e8cf6e34edd45d0aa Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Mon, 15 Jul 2013 22:01:36 +0200 Subject: Keep priorities from diverging Priorities should always be a sequence... --- pg-datastore.lisp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pg-datastore.lisp b/pg-datastore.lisp index 805e748..260902e 100644 --- a/pg-datastore.lisp +++ b/pg-datastore.lisp @@ -94,8 +94,11 @@ :where (:= 'id id)) :single)) (next-priority (funcall (ecase dir (:up #'-) (:down #'+)) - current-priority 1))) + current-priority 1)) + (max-priority (query (:select (:max 'priority) :from type) + :single))) (execute (:update type :set 'priority current-priority :where (:= 'priority next-priority))) - (execute (:update type :set 'priority next-priority + (execute (:update type :set + 'priority (max 1 (min next-priority max-priority)) :where (:= 'id id)))))) -- cgit v1.2.3-54-g00ecf