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:
@@ -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;
|
||||
Reference in New Issue
Block a user