mirror of
https://github.com/Sonny93/my-links.git
synced 2025-12-10 07:25:35 +00:00
Reorder categories (#12)
* feat: add next category id column * feat: reorder categories (front) * refactor: remove dead code & some optimization * feat(wip): add order column + sql request + trigger * refactor: fix warnings * fix: syntax error in migration * feat: create sql query (category reorder) * feat: use prisma generated types instead * feat: create some react context with hooks * refactor: move a lot of code from home page to dedicated components * refactor: extend generated prisma types * refactor: use hooks and move links footer in dedicated component * refactor: fix bad types used * fix: warnings caused by setState loop * feat: use nextid instead of order column * fix: reorder categories (front) * fix: sort categories by nextId * feat: prevent send update request if cat.id equal target.id * fix: reorganization applied even if there is no change * chore: remove unused en var * feat: check if nextid category exist * chore: sql query for migration * refactor: remove useless code and prevent sending request when category not moving * fix: redorder categories when sending request
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE `category` ADD COLUMN `nextId` INTEGER NULL;
|
||||
|
||||
10
prisma/queries/set_default_next_id.sql
Normal file
10
prisma/queries/set_default_next_id.sql
Normal file
@@ -0,0 +1,10 @@
|
||||
-- set default next id for each category based on LEAD(id) (LEAD -> Next)
|
||||
|
||||
UPDATE Category AS c
|
||||
JOIN (
|
||||
SELECT
|
||||
id,
|
||||
LEAD(id) OVER (PARTITION BY authorId ORDER BY id) AS nextCategoryId
|
||||
FROM Category
|
||||
) AS n ON c.id = n.id
|
||||
SET c.nextId = n.nextCategoryId;
|
||||
@@ -33,6 +33,8 @@ model Category {
|
||||
author User @relation(fields: [authorId], references: [id])
|
||||
authorId Int
|
||||
|
||||
nextId Int?
|
||||
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
|
||||
Reference in New Issue
Block a user