qiangdanxitong/database/fix_category_is_leaf.sql

40 lines
1.2 KiB
SQL
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- 修复 category 表的 is_leaf 字段问题
-- 问题:创建的类目 is_leaf 字段为 0,导致在发布任务时无法选择
-- 解决:将类目设置为叶子节点(is_leaf = 1)
-- 日期:2026-01-02
USE designhub;
-- 修复现有的类目数据,将它们设置为叶子节点
UPDATE category
SET is_leaf = 1
WHERE deleted = 0
AND is_leaf = 0;
-- 验证修改结果
SELECT
id,
category_name,
parent_id,
level,
is_leaf,
status,
create_time
FROM
category
WHERE
deleted = 0
ORDER BY
sort_order, id;
-- 说明:
-- 1. is_leaf = 1 表示叶子节点(最底层的类目,可以直接用于任务)
-- 2. is_leaf = 0 表示父节点(有子类目的分类,不能直接用于任务)
-- 3. 发布任务时只能选择叶子类目(is_leaf = 1 且 status = 1)
-- 4. 如果您的类目需要分层级(如:家具 > 桌子 > 电脑桌),则:
-- - 一级类目(家具): is_leaf = 0, level = 1, parent_id = 0
-- - 二级类目(桌子): is_leaf = 0, level = 2, parent_id = 家具的id
-- - 三级类目(电脑桌): is_leaf = 1, level = 3, parent_id = 桌子的id
-- 5. 如果您的类目不需要分层级,直接设置为叶子节点即可