Files
xuanzhi-service/server/.ai-transition/database-upgrade-doc/v1.sql
wdh-home 1e33640629
Some checks failed
CI / init (pull_request) Has been cancelled
CI / Frontend node 18.16.0 (pull_request) Has been cancelled
CI / Backend go (1.22) (pull_request) Has been cancelled
CI / release-pr (pull_request) Has been cancelled
CI / devops-test (1.22, 18.16.0) (pull_request) Has been cancelled
CI / release-please (pull_request) Has been cancelled
CI / devops-prod (1.22, 18.x) (pull_request) Has been cancelled
CI / docker (pull_request) Has been cancelled
基础项目
2026-04-26 15:32:21 +08:00

133 lines
5.5 KiB
Go

-- API 权限分配接口初始化补齐 / sys_apis, casbin_rule / 2026-04-25
INSERT INTO sys_apis (created_at, updated_at, path, description, api_group, method)
SELECT NOW(), NOW(), '/api/getApiRoles', '获取API关联角色ID列表', 'api', 'GET'
WHERE NOT EXISTS (
SELECT 1 FROM sys_apis WHERE path = '/api/getApiRoles' AND method = 'GET'
);
INSERT INTO sys_apis (created_at, updated_at, path, description, api_group, method)
SELECT NOW(), NOW(), '/api/setApiRoles', '全量覆盖API关联角色', 'api', 'POST'
WHERE NOT EXISTS (
SELECT 1 FROM sys_apis WHERE path = '/api/setApiRoles' AND method = 'POST'
);
INSERT INTO casbin_rule (ptype, v0, v1, v2)
SELECT 'p', '888', '/api/getApiRoles', 'GET'
WHERE NOT EXISTS (
SELECT 1 FROM casbin_rule
WHERE ptype = 'p' AND v0 = '888' AND v1 = '/api/getApiRoles' AND v2 = 'GET'
);
INSERT INTO casbin_rule (ptype, v0, v1, v2)
SELECT 'p', '888', '/api/setApiRoles', 'POST'
WHERE NOT EXISTS (
SELECT 1 FROM casbin_rule
WHERE ptype = 'p' AND v0 = '888' AND v1 = '/api/setApiRoles' AND v2 = 'POST'
);
-- book 业务字典初始化补齐 / sys_dictionaries, sys_dictionary_details / 2026-04-26
WITH dict_seed(name, type, status, description) AS (
VALUES
('作者状态', 'book_author_status', true, '作者状态字典'),
('书籍评论状态', 'book_comment_status', true, '书籍评论状态字典'),
('书籍完结状态', 'book_completion_status', true, '书籍完结状态字典'),
('书籍时代标签', 'book_era_tag', true, '书籍时代标签字典'),
('书籍上下架状态', 'book_publish_status', true, '书籍上下架状态字典'),
('书籍类型', 'book_type', true, '书籍类型动态字典')
)
UPDATE sys_dictionaries d
SET name = s.name,
status = s.status,
"desc" = s.description,
updated_at = NOW(),
deleted_at = NULL
FROM dict_seed s
WHERE d.type = s.type;
WITH dict_seed(name, type, status, description) AS (
VALUES
('作者状态', 'book_author_status', true, '作者状态字典'),
('书籍评论状态', 'book_comment_status', true, '书籍评论状态字典'),
('书籍完结状态', 'book_completion_status', true, '书籍完结状态字典'),
('书籍时代标签', 'book_era_tag', true, '书籍时代标签字典'),
('书籍上下架状态', 'book_publish_status', true, '书籍上下架状态字典'),
('书籍类型', 'book_type', true, '书籍类型动态字典')
)
INSERT INTO sys_dictionaries (created_at, updated_at, name, type, status, "desc")
SELECT NOW(), NOW(), s.name, s.type, s.status, s.description
FROM dict_seed s
WHERE NOT EXISTS (
SELECT 1 FROM sys_dictionaries d WHERE d.type = s.type
);
WITH detail_seed(dict_type, label, value, sort, status) AS (
VALUES
('book_author_status', '启用', 'enabled', 10, true),
('book_author_status', '禁用', 'disabled', 20, true),
('book_comment_status', '正常', 'normal', 10, true),
('book_comment_status', '隐藏', 'hidden', 20, true),
('book_completion_status', '完结', 'completed', 10, true),
('book_completion_status', '连载', 'serializing', 20, true),
('book_era_tag', '未知时代', 'unknown', 10, true),
('book_era_tag', '远古', 'ancient', 20, true),
('book_era_tag', '汉', 'han', 30, true),
('book_era_tag', '唐', 'tang', 40, true),
('book_era_tag', '宋', 'song', 50, true),
('book_era_tag', '元', 'yuan', 60, true),
('book_era_tag', '明', 'ming', 70, true),
('book_era_tag', '清', 'qing', 80, true),
('book_era_tag', '近代', 'modern', 90, true),
('book_era_tag', '现代', 'contemporary', 100, true),
('book_publish_status', '草稿', 'draft', 10, true),
('book_publish_status', '下架', 'off_shelf', 20, true),
('book_publish_status', '上架', 'on_shelf', 30, true)
)
UPDATE sys_dictionary_details d
SET label = s.label,
sort = s.sort,
status = s.status,
extend = '',
level = 0,
path = '',
updated_at = NOW(),
deleted_at = NULL
FROM detail_seed s
JOIN sys_dictionaries dict ON dict.type = s.dict_type
WHERE d.sys_dictionary_id = dict.id
AND d.value = s.value;
WITH detail_seed(dict_type, label, value, sort, status) AS (
VALUES
('book_author_status', '启用', 'enabled', 10, true),
('book_author_status', '禁用', 'disabled', 20, true),
('book_comment_status', '正常', 'normal', 10, true),
('book_comment_status', '隐藏', 'hidden', 20, true),
('book_completion_status', '完结', 'completed', 10, true),
('book_completion_status', '连载', 'serializing', 20, true),
('book_era_tag', '未知时代', 'unknown', 10, true),
('book_era_tag', '远古', 'ancient', 20, true),
('book_era_tag', '汉', 'han', 30, true),
('book_era_tag', '唐', 'tang', 40, true),
('book_era_tag', '宋', 'song', 50, true),
('book_era_tag', '元', 'yuan', 60, true),
('book_era_tag', '明', 'ming', 70, true),
('book_era_tag', '清', 'qing', 80, true),
('book_era_tag', '近代', 'modern', 90, true),
('book_era_tag', '现代', 'contemporary', 100, true),
('book_publish_status', '草稿', 'draft', 10, true),
('book_publish_status', '下架', 'off_shelf', 20, true),
('book_publish_status', '上架', 'on_shelf', 30, true)
)
INSERT INTO sys_dictionary_details (created_at, updated_at, label, value, extend, status, sort, sys_dictionary_id, level, path)
SELECT NOW(), NOW(), s.label, s.value, '', s.status, s.sort, dict.id, 0, ''
FROM detail_seed s
JOIN sys_dictionaries dict ON dict.type = s.dict_type
WHERE NOT EXISTS (
SELECT 1
FROM sys_dictionary_details d
WHERE d.sys_dictionary_id = dict.id
AND d.value = s.value
);