chore: update book enabled status wiring

This commit is contained in:
2026-04-27 11:41:35 +08:00
parent 93bde0a6b6
commit 67c33d06be
25 changed files with 336 additions and 122 deletions

View File

@@ -38,7 +38,6 @@ WHERE type = 'book_author_status';
WITH dict_seed(name, type, status, description) AS (
VALUES
('通用启用状态', 'common_enabled_status', true, '通用启用禁用状态字典'),
('书籍评论状态', 'book_comment_status', true, '书籍评论状态字典'),
('书籍完结状态', 'book_completion_status', true, '书籍完结状态字典'),
('书籍时代标签', 'book_era_tag', true, '书籍时代标签字典'),
@@ -56,7 +55,6 @@ WHERE d.type = s.type;
WITH dict_seed(name, type, status, description) AS (
VALUES
('通用启用状态', 'common_enabled_status', true, '通用启用禁用状态字典'),
('书籍评论状态', 'book_comment_status', true, '书籍评论状态字典'),
('书籍完结状态', 'book_completion_status', true, '书籍完结状态字典'),
('书籍时代标签', 'book_era_tag', true, '书籍时代标签字典'),
@@ -72,8 +70,6 @@ WHERE NOT EXISTS (
WITH detail_seed(dict_type, label, value, sort, status) AS (
VALUES
('common_enabled_status', '启用', 'enabled', 10, true),
('common_enabled_status', '禁用', 'disabled', 20, true),
('book_comment_status', '正常', 'normal', 10, true),
('book_comment_status', '隐藏', 'hidden', 20, true),
('book_completion_status', '完结', 'completed', 10, true),
@@ -108,8 +104,6 @@ WHERE d.sys_dictionary_id = dict.id
WITH detail_seed(dict_type, label, value, sort, status) AS (
VALUES
('common_enabled_status', '启用', 'enabled', 10, true),
('common_enabled_status', '禁用', 'disabled', 20, true),
('book_comment_status', '正常', 'normal', 10, true),
('book_comment_status', '隐藏', 'hidden', 20, true),
('book_completion_status', '完结', 'completed', 10, true),
@@ -138,3 +132,55 @@ WHERE NOT EXISTS (
WHERE d.sys_dictionary_id = dict.id
AND d.value = s.value
);
-- 作者启停字段统一为 is_enabled bool / book_author, sys_dictionaries, sys_dictionary_details / 2026-04-27
DO $$
BEGIN
IF to_regclass('public.book_author') IS NOT NULL THEN
ALTER TABLE book_author
ADD COLUMN IF NOT EXISTS is_enabled boolean;
IF EXISTS (
SELECT 1
FROM information_schema.columns
WHERE table_schema = 'public'
AND table_name = 'book_author'
AND column_name = 'author_status'
) THEN
UPDATE book_author
SET is_enabled = CASE WHEN author_status = 'disabled' THEN false ELSE true END
WHERE is_enabled IS NULL;
ELSE
UPDATE book_author
SET is_enabled = true
WHERE is_enabled IS NULL;
END IF;
ALTER TABLE book_author
ALTER COLUMN is_enabled SET DEFAULT true;
ALTER TABLE book_author
ALTER COLUMN is_enabled SET NOT NULL;
COMMENT ON COLUMN book_author.is_enabled IS '作者是否启用';
DROP INDEX IF EXISTS idx_book_author_author_status;
CREATE INDEX IF NOT EXISTS idx_book_author_is_enabled ON book_author (is_enabled);
ALTER TABLE book_author
DROP COLUMN IF EXISTS author_status;
END IF;
END $$;
UPDATE sys_dictionary_details d
SET status = false,
updated_at = NOW()
FROM sys_dictionaries dict
WHERE d.sys_dictionary_id = dict.id
AND dict.type = 'common_enabled_status';
UPDATE sys_dictionaries
SET status = false,
updated_at = NOW()
WHERE type = 'common_enabled_status';