chore(init): 初始化解忧商行项目并完成 Phase 0 基座
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
-- +goose Up
|
||||
|
||||
CREATE TABLE IF NOT EXISTS cs_manual_entries (
|
||||
id BIGINT UNSIGNED PRIMARY KEY AUTO_INCREMENT,
|
||||
entry_no VARCHAR(64) NOT NULL COMMENT '客服录入的编号',
|
||||
admin_id BIGINT UNSIGNED NOT NULL COMMENT '录单客服管理员ID',
|
||||
admin_name VARCHAR(64) NOT NULL DEFAULT '' COMMENT '客服昵称快照',
|
||||
admin_username VARCHAR(64) NOT NULL DEFAULT '' COMMENT '客服登录名快照',
|
||||
remark VARCHAR(255) NOT NULL DEFAULT '' COMMENT '备注',
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '登记时间',
|
||||
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
UNIQUE KEY uk_cs_manual_entries_entry_no (entry_no),
|
||||
KEY idx_cs_manual_entries_admin_created (admin_id, created_at),
|
||||
KEY idx_cs_manual_entries_created_at (created_at)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='客服手动录单记录表';
|
||||
|
||||
INSERT INTO permissions (code, name, resource, action) VALUES
|
||||
('cs_manual_entry:view', '查看客服手动录单', 'cs_manual_entry', 'view'),
|
||||
('cs_manual_entry:create', '客服手动录单', 'cs_manual_entry', 'create'),
|
||||
('cs_manual_entry:update', '编辑客服手动录单', 'cs_manual_entry', 'update'),
|
||||
('cs_manual_entry:delete', '删除客服手动录单', 'cs_manual_entry', 'delete')
|
||||
ON DUPLICATE KEY UPDATE
|
||||
name = VALUES(name),
|
||||
resource = VALUES(resource),
|
||||
action = VALUES(action);
|
||||
|
||||
-- 客服/运营/超管:录单 + 查询
|
||||
INSERT IGNORE INTO role_permissions (role_id, permission_id)
|
||||
SELECT r.id, p.id
|
||||
FROM roles r
|
||||
JOIN permissions p ON p.code IN ('cs_manual_entry:view', 'cs_manual_entry:create')
|
||||
WHERE r.code IN ('cs', 'ops', 'super_admin');
|
||||
|
||||
-- 运营/超管:全量 CRUD(编辑、删除)
|
||||
INSERT IGNORE INTO role_permissions (role_id, permission_id)
|
||||
SELECT r.id, p.id
|
||||
FROM roles r
|
||||
JOIN permissions p ON p.code IN ('cs_manual_entry:update', 'cs_manual_entry:delete')
|
||||
WHERE r.code IN ('ops', 'super_admin');
|
||||
|
||||
-- +goose Down
|
||||
|
||||
DELETE rp
|
||||
FROM role_permissions rp
|
||||
JOIN permissions p ON p.id = rp.permission_id
|
||||
WHERE p.code IN ('cs_manual_entry:view', 'cs_manual_entry:create', 'cs_manual_entry:update', 'cs_manual_entry:delete');
|
||||
|
||||
DELETE FROM permissions WHERE code IN ('cs_manual_entry:view', 'cs_manual_entry:create', 'cs_manual_entry:update', 'cs_manual_entry:delete');
|
||||
|
||||
DROP TABLE IF EXISTS cs_manual_entries;
|
||||
Reference in New Issue
Block a user