mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
New label's position is in alphabetic order
This commit is contained in:
parent
4916bdf1f3
commit
611c323ee0
1 changed files with 2 additions and 1 deletions
|
|
@ -29,7 +29,8 @@ CREATE OR REPLACE FUNCTION update_label_position()
|
|||
UPDATE omnivore.labels SET position = position - 1 WHERE user_id = OLD.user_id AND position > OLD.position;
|
||||
RETURN OLD;
|
||||
ELSIF (TG_OP = 'INSERT') THEN
|
||||
SELECT COALESCE(MAX(position), 0) + 1 INTO new_position FROM omnivore.labels WHERE user_id = NEW.user_id;
|
||||
SELECT COALESCE(MAX(position), 0) + 1 INTO new_position FROM omnivore.labels WHERE user_id = NEW.user_id AND name < NEW.name;
|
||||
UPDATE omnivore.labels SET position = position + 1 WHERE user_id = NEW.user_id AND position >= new_position;
|
||||
NEW.position = new_position;
|
||||
RETURN NEW;
|
||||
END IF;
|
||||
|
|
|
|||
Loading…
Reference in a new issue