feat(brand): add brand sort order and drag-to-reorder

Add a sort_order column to brands with a migration, expose a
PUT /api/tenant/brands/order reorder endpoint, and wire the
admin-web BrandsView with drag-and-drop reordering plus i18n.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-07-08 21:48:20 +08:00
parent fbc69c01b0
commit 71233b6715
16 changed files with 608 additions and 31 deletions
@@ -0,0 +1,4 @@
DROP INDEX IF EXISTS idx_brands_tenant_sort_active;
ALTER TABLE brands
DROP COLUMN IF EXISTS sort_order;
@@ -0,0 +1,24 @@
ALTER TABLE brands
ADD COLUMN sort_order INT;
WITH ordered_brands AS (
SELECT
id,
ROW_NUMBER() OVER (
PARTITION BY tenant_id
ORDER BY created_at DESC, id DESC
)::INT * 1000 AS next_sort_order
FROM brands
)
UPDATE brands
SET sort_order = ordered_brands.next_sort_order
FROM ordered_brands
WHERE brands.id = ordered_brands.id;
ALTER TABLE brands
ALTER COLUMN sort_order SET DEFAULT 1000,
ALTER COLUMN sort_order SET NOT NULL;
CREATE INDEX idx_brands_tenant_sort_active
ON brands(tenant_id, sort_order ASC, created_at DESC, id DESC)
WHERE deleted_at IS NULL;