Assign category positions inside the database

A new category's position is computed by its insert, one after the highest, so two categories created at once can't take the same one. Inserts take a NewCategory rather than a Category whose id and position would be ignored. Reordering places any category missing from the given order after the rest instead of leaving it at a stale position. Restore still creates missing categories all or none, in backup order, and the create dialog no longer accepts an empty name.
This commit is contained in:
AntsyLich
2026-09-27 22:53:09 +06:00
parent fc5592ff75
commit 8bfa495f34
8 changed files with 42 additions and 46 deletions
@@ -44,7 +44,8 @@ WHERE MC.manga_id = :mangaId;
insert:
INSERT INTO categories(name, sort, flags)
VALUES (:name, :order, :flags);
SELECT :name, coalesce(max(sort), -1) + 1, :flags
FROM categories;
delete:
DELETE FROM categories
@@ -55,6 +56,12 @@ UPDATE categories
SET name = :name
WHERE _id = :categoryId;
getUserCategoryIds:
SELECT _id
FROM categories
WHERE _id > 0
ORDER BY sort;
updateOrder:
UPDATE categories
SET sort = :order