码巢引擎2026年开发文档
00-开发规范
后端规范
README
后端开发手册
前端规范
README
TypeScript最佳实践
前端布局规范
前端页面模板
前端颜色与组件规范
核心规范
组件配置手册
问题排查指南
页面模板
最佳实践
README
bp-20260223-m7ps
图片上传优化总结
BUG自动记录系统使用指南
README
TYPE_SAFETY_GUIDE
常见BUG知识库
常见BUG知识库
开发前检查清单
开发安全规范
开发规范-完整版-含FutureBirdAadminAi部署
数据模型字典
文档分类规范
文档标准化规范
文档模板-基础版
文档模板-技术版
类型安全快速参考卡
类型安全规范体系
规范更新指南
过期文档清理机制
错误处理规范
错误预防指南
常见BUG知识库
常见BUG知识库
01-快速开始
Gitee快速开始
README
协作快速开始
快速开始
质量保证快速开始
02-部署指南
Docker更新指南
Docker部署
FutureBirdAadminAi部署指南
FutureBirdAadminAi部署问题分析
README
发布指南
宝塔Docker部署教程
宝塔PM2部署教程
宝塔图形化部署教程
快速发布指南
数据库和依赖变更处理指南
构建和发布
构建标准
构建检查清单
生产部署快速开始
生产部署方案
生产部署标准
生产部署检查清单
程序备份性能
自动修复和发布指南
自动化发布命令使用指南
部署快速开始
部署指南
项目更新部署指南
03-开发指南
Git凭据配置
Git推送规则
Git自动配置
README
全局样式
协作设置
定时任务
开发指南
开发流程
开发环境标准
技术改进
贡献指南
项目目录树
项目目录结构
04-API文档
API接口文档
README
hr-api
企业API
05-数据库
DATABASE_SCHEMA
README
分区指南
数据库字典
数据持久化
数据模型统一
数据迁移
06-架构设计
RBAC-PERMISSIONS
README
SaaS客户引导流程设计
companyId统一规范
employee-permission-system-design
enterprise-data-linkage
仓库实现总结
仓库模式
企业管理端员工权限系统分析
前端架构
前端重构总结
员工权限系统评估报告
员工管理菜单重构方案
权限系统混乱问题分析
架构优化计划
架构使用指南
架构结构
架构结构
状态管理
用户身份管理体系
系统架构
面试管理模块重构规划
项目技术栈
07-测试质量
README
测试修复标准
测试报告
质量保证系统
08-版本管理
CHANGELOG
README
VERSION_RULES
09-配置指南
README
SMTP配置指南
主题切换指南
渠道配置指南
环境变量指南
环境隔离
12-项目记忆
README
知识库导入指南
记忆系统指南
13-迁移指南
README
备份迁移指南
管理员迁移指南
迁移快速开始
17-其他
README
压缩摘要
18-开放平台
01-架构设计
02-API接口设计
03-安全机制
04-前端设计
05-数据库设计
开放平台API指南
开放平台API说明
19-智能进化
AI执行规则
AI进化机制
README
自动化实现总览
黄金规则
40-操作教程
README
微信公众号域名配置指南
微信本地开发调试指南
44-技能文件
alipay-payment-integration
references
checklist
SKILL
audio
python
README
typescript
README
SKILL
database
python
README
typescript
README
SKILL
design-style-thinking
SKILL
doctor
references
sql-patterns
SKILL
document-generation
python
README
SKILL
email
SKILL
embedding
python
README
typescript
README
SKILL
expo-advanced
references
audio-record-play
file-upload
masonry-layout
save-to-gallery
top-tab-navigation
SKILL
feishu-base
SKILL
feishu-message
SKILL
fetch-url
python
README
typescript
README
SKILL
frontend-design
LICENSE
SKILL
FutureBird-coding-web-performance-best-practice
SKILL
general-dev-preview
references
web-preview
SKILL
image-generation
python
README
typescript
README
SKILL
knowledge
references
python
README
typescript
README
cli
SKILL
llm
python
README
typescript
README
SKILL
miniapp-upload-asr
SKILL
pptx-generation
python
README
SKILL
project-memory-loader
scripts
project_memory_loader
SKILL
repair
scripts
merge-commit-map
SKILL
shadcn-web-base-theme
assets
colors
amber
artistic-green
bento-blue
blue
cyan
emerald
fuchsia
gray
green
indigo
lime
low-pink
neutral
orange
purple
red
retro-brown
rose
sky
supbase-green
teal
tech-purple
vintage-grey
violet
yellow
fonts
business
classic
playful
radius
2xl
2xs
lg
md
none
sm
xl
xs
shadow
artistic
bento
cool
retro
superbase
tech
tool
vintage
default
references
colors
fonts
quick
radius
shadows
scripts
theme
SKILL
package
skill-creator-coze
scripts
init_skill
quick_validate
SKILL
storage
python
README
typescript
README
SKILL
supabase
assets
supabase-client
supabase-client
references
_future
asset-supabase-browser
asset-supabase-config-inject
asset-supabase-config-route
python-auth
python-realtime
python-storage
typescript-auth
typescript-realtime
typescript-storage
typescript-supabase-browser
typescript-supabase-config-inject
typescript-supabase-config-route
python
README
database
edge-functions
orm-model-guide
supabase_client
typescript
README
database
drizzle-schema-guide
edge-functions
supabase-client
cli
rls
SKILL
supabase-auth
references
typescript
supabase-browser
supabase-config-inject
supabase-config-route
auth-config
verify-session
SKILL
ui-design-ref
reference
3D黏土风
克莱因蓝高定风
暗黑科技风
杂志风
极光柔和
柔和卡片
玻璃拟态
纯白极简风
自然有机
SKILL
ui-ux-pro-max
scripts
core
design_system
search
SKILL
vercel-composition-patterns
rules
architecture-avoid-boolean-props
architecture-compound-components
patterns-children-over-render-props
patterns-explicit-variants
react19-no-forwardref
state-context-interface
state-decouple-implementation
state-lift-state
AGENTS
SKILL
vercel-react-best-practices
rules
advanced-event-handler-refs
advanced-init-once
advanced-use-latest
async-api-routes
async-defer-await
async-dependencies
async-parallel
async-suspense-boundaries
bundle-barrel-imports
bundle-conditional
bundle-defer-third-party
bundle-dynamic-imports
bundle-preload
client-event-listeners
client-localstorage-schema
client-passive-event-listeners
client-swr-dedup
js-batch-dom-css
js-cache-function-results
js-cache-property-access
js-cache-storage
js-combine-iterations
js-early-exit
js-hoist-regexp
js-index-maps
js-length-check-first
js-min-max-loop
js-set-map-lookups
js-tosorted-immutable
rendering-activity
rendering-animate-svg-wrapper
rendering-conditional-render
rendering-content-visibility
rendering-hoist-jsx
rendering-hydration-no-flicker
rendering-hydration-suppress-warning
rendering-svg-precision
rendering-usetransition-loading
rerender-defer-reads
rerender-dependencies
rerender-derived-state-no-effect
rerender-derived-state
rerender-functional-setstate
rerender-lazy-state-init
rerender-memo-with-default-value
rerender-memo
rerender-move-effect-to-event
rerender-simple-expression-in-memo
rerender-transitions
rerender-use-ref-transient-values
server-auth-actions
server-cache-lru
server-cache-react
server-dedup-props
server-parallel-fetching
server-serialization
AGENTS
SKILL
video-edit
python
README
typescript
README
SKILL
video-generation
python
README
typescript
README
SKILL
volcano-ark
SKILL
web-design-guidelines
SKILL
web-search
python
README
typescript
README
SKILL
webrtc-best-practice
SKILL
websocket-guide
references
nextjs
nodejs
SKILL
wechat-bot
SKILL
wechat-official-account
SKILL
README
README
未来鸟:企业数字化转型奔腾的力量!
-
+
首页
架构优化计划
> **文档版本**: v1.0.0 > **创建日期**: 2026-02-12 > **最后更新**: 2026-02-12 > **维护人**: 未来鸟FutureBird码巢企业服务引擎开发组 > **状态**: [最新] --- # Schema 统一优化方案 ## 📊 当前状态分析 ### 问题描述 项目中存在两个独立的 schema 定义文件,导致: 1. 代码维护困难 2. 容易产生不一致 3. 引用路径混乱 4. 新人难以理解项目结构 ### 文件对比 | 文件 | 大小 | 表数量 | 引用次数 | |------|------|--------|----------| | `src/infrastructure/database/shared/schema.ts` | 91KB | 53个 | 8次 | | `src/storage/database/shared/schema.ts` | 69KB | 48个 | 30次 | ### 差异分析 #### Infrastructure 独有的表(23个) ``` apiAlertHistories - API 警报历史 apiAlertRules - API 警报规则 apiMonitorLogs - API 监控日志 apiMonitorMetrics - API 监控指标 channelConfigs - 渠道配置 invitationRecords - 邀请记录 marketActivationCodes - 市场激活码 marketCategories - 市场分类 marketOrders - 市场订单 mediaCategories - 媒体分类 mediaResources - 媒体资源 miniprogramLoginLogs - 小程序登录日志 miniprogramUsers - 小程序用户 salaryNotifyRecords - 薪资通知记录 salaryNotifyTemplates - 薪资通知模板 surveyVotes - 投票记录 userInstalledApps - 用户安装的应用 wechatAutoReplies - 微信自动回复 wechatFans - 微信粉丝 wechatMenus - 微信菜单 wechatMessages - 微信消息 wechatReplies - 微信回复 wechatTemplates - 微信模板 weworkApps - 企业应用 weworkAuthCorps - 企业认证企业 weworkDepartments - 企业部门 weworkUsers - 企业用户 ``` #### Storage 独有的表(22个) ``` emailGlobalVariables - 邮件全局变量 emailTemplateVersions - 邮件模板版本 emailTriggerConfigs - 邮件触发配置 employeeExportPermissions - 员工导出权限 employeePermissionLogs - 员工权限日志 employees - 员工表 loginPageConfigs - 登录页配置 marketReviews - 市场评论 orders - 订单(新版本) partners - 合作伙伴 payrollDetails - 工资单明细 payrollSheets - 工资单 platformConfig - 平台配置 rolePermissions - 角色权限 smsQuota - 短信配额 smsRechargeRecords - 短信充值记录 smsSendRecords - 短信发送记录 smsServiceConfig - 短信服务配置 smsTemplates - 短信模板 smsVerificationCodes - 短信验证码 smtpConfigs - SMTP 配置 tenants - 租户(新版本) ``` #### 共同的表(26个) ``` appPermissions companyApps crmFollowRecords dataExports emailSendRecords emailTemplates employeeFeedback employeeSocialInsurance globalPaymentConfigs globalPaymentRecords notificationSettings saasCompanies saasOrders saasTenants saasUsers salaryConfigs salaryItemConfigs salarySlipDetails salarySlipSends salarySlips socialInsuranceConfigs systemSettings taxRateTables tenantTransactions users ``` --- ## 🎯 优化方案 ### 方案 A:统一到 Storage Schema(推荐) #### 优点 - ✅ Storage schema 引用次数更多(30 vs 8) - ✅ 文件更小(69KB vs 91KB) - ✅ 包含更多现代业务表(SMS、Email 配置等) - ✅ 影响范围较小 #### 执行步骤 1. 将 Infrastructure 独有的 23 个表迁移到 Storage schema 2. 更新所有引用 Infrastructure schema 的文件(8个) 3. 删除 Infrastructure schema 文件 4. 更新 Drizzle 配置 5. 验证构建和运行 #### 影响范围 - 需要修改的文件:约 8 个 - 需要迁移的表:23 个 - 预计工作量:2-3 小时 --- ### 方案 B:按模块拆分 #### 优点 - ✅ 清晰的模块划分 - ✅ 易于管理大型项目 - ✅ 降低单文件复杂度 #### 执行步骤 1. 创建多个 schema 文件: - `schema-core.ts` - 核心表(users, tenants, companies 等) - `schema-salary.ts` - 薪资相关表 - `schema-communication.ts` - 通信相关表(Email, SMS, WeChat) - `schema-crm.ts` - CRM 相关表 - `schema-monitor.ts` - 监控相关表 2. 创建统一的索引文件 `index.ts` 3. 更新所有引用 4. 验证构建 #### 影响范围 - 需要修改的文件:约 40 个 - 需要创建的文件:6 个 - 预计工作量:4-6 小时 --- ### 方案 C:保持现状 + 添加注释 #### 优点 - ✅ 无需修改代码 - ✅ 零风险 #### 缺点 - ❌ 没有解决实际问题 - ❌ 维护困难 --- ## 💡 推荐方案:方案 A ### 理由 1. **影响最小**:只需修改 8 个文件 2. **效果显著**:统一后维护更容易 3. **风险可控**:Storage schema 已经被广泛使用 4. **可扩展**:未来如果需要再拆分,可以从统一的基础上进行 ### 详细步骤 #### 第 1 步:备份当前文件 ```bash cp src/infrastructure/database/shared/schema.ts src/infrastructure/database/shared/schema.ts.backup cp src/storage/database/shared/schema.ts src/storage/database/shared/schema.ts.backup ``` #### 第 2 步:迁移 Infrastructure 独有的表到 Storage ```typescript // 在 src/storage/database/shared/schema.ts 末尾添加 // ==================== API 监控相关 ==================== export const apiAlertHistories = pgTable("api_alert_histories", { ... }); export const apiAlertRules = pgTable("api_alert_rules", { ... }); export const apiMonitorLogs = pgTable("api_monitor_logs", { ... }); export const apiMonitorMetrics = pgTable("api_monitor_metrics", { ... }); // ==================== 渠道相关 ==================== export const channelConfigs = pgTable("channel_configs", { ... }); // ==================== 市场相关 ==================== export const marketActivationCodes = pgTable("market_activation_codes", { ... }); export const marketCategories = pgTable("market_categories", { ... }); export const marketOrders = pgTable("market_orders", { ... }); // ==================== 媒体相关 ==================== export const mediaCategories = pgTable("media_categories", { ... }); export const mediaResources = pgTable("media_resources", { ... }); // ==================== 小程序相关 ==================== export const miniprogramLoginLogs = pgTable("miniprogram_login_logs", { ... }); export const miniprogramUsers = pgTable("miniprogram_users", { ... }); // ==================== 薪资通知相关 ==================== export const salaryNotifyRecords = pgTable("salary_notify_records", { ... }); export const salaryNotifyTemplates = pgTable("salary_notify_templates", { ... }); // ==================== 投票相关 ==================== export const surveyVotes = pgTable("survey_votes", { ... }); // ==================== 用户应用相关 ==================== export const userInstalledApps = pgTable("user_installed_apps", { ... }); // ==================== 微信相关 ==================== export const wechatAutoReplies = pgTable("wechat_auto_replies", { ... }); export const wechatFans = pgTable("wechat_fans", { ... }); export const wechatMenus = pgTable("wechat_menus", { ... }); export const wechatMessages = pgTable("wechat_messages", { ... }); export const wechatReplies = pgTable("wechat_replies", { ... }); export const wechatTemplates = pgTable("wechat_templates", { ... }); // ==================== 企业微信相关 ==================== export const weworkApps = pgTable("wework_apps", { ... }); export const weworkAuthCorps = pgTable("wework_auth_corps", { ... }); export const weworkDepartments = pgTable("wework_departments", { ... }); export const weworkUsers = pgTable("wework_users", { ... }); ``` #### 第 3 步:更新引用路径 需要修改以下文件: ``` src/infrastructure/scheduler/index.ts src/infrastructure/scheduler/salarySlipScheduler.ts src/infrastructure/database/repositories/SalarySlipRepository.ts src/infrastructure/database/repositories/SalarySlipSendRepository.ts src/infrastructure/database/repositories/TenantRepository.ts src/infrastructure/database/repositories/UserRepository.ts src/infrastructure/database/repositories/CompanyRepository.ts src/infrastructure/repositories/PaymentRepository.ts ``` 将所有: ```typescript import { ... } from '@/infrastructure/database/shared/schema'; ``` 改为: ```typescript import { ... } from '@/storage/database/shared/schema'; ``` #### 第 4 步:删除 Infrastructure schema ```bash rm src/infrastructure/database/shared/schema.ts rm src/infrastructure/database/shared/schema-legacy.ts ``` #### 第 5 步:更新 Drizzle 配置 ```typescript // drizzle.config.ts export default defineConfig({ schema: './src/storage/database/shared/schema.ts', // 改为 storage out: './drizzle', driver: 'pg', dbCredentials: { connectionString: process.env.DATABASE_URL || 'postgresql://...', }, }); ``` #### 第 6 步:验证 ```bash # 1. 检查类型 npx tsc --noEmit # 2. 构建项目 npx next build # 3. 运行测试 pnpm test # 如果有的话 ``` --- ## ⚠️ 风险评估 | 风险 | 等级 | 缓解措施 | |------|------|----------| | 类型错误 | 中 | 先运行 tsc 检查 | | 运行时错误 | 低 | 充分测试 | | 数据库迁移 | 无 | 仅代码变更,不涉及数据库 | | 破坏性变更 | 低 | 内容完全相同,只是路径改变 | --- ## 📋 检查清单 - [ ] 备份现有 schema 文件 - [ ] 迁移 Infrastructure 独有的表 - [ ] 更新所有引用路径(8 个文件) - [ ] 删除 Infrastructure schema - [ ] 更新 Drizzle 配置 - [ ] 运行类型检查 - [ ] 执行构建测试 - [ ] 验证应用运行 - [ ] 更新文档 --- ## 🎯 预期效果 - ✅ 统一 schema 定义 - ✅ 减少维护成本 - ✅ 提高代码清晰度 - ✅ 降低新人学习成本 - ✅ 为未来优化(如按模块拆分)打好基础 --- ## 📅 执行时间表 - **准备阶段**:30 分钟(备份、分析) - **执行阶段**:1-2 小时(迁移、修改) - **测试阶段**:30 分钟(验证) - **总计**:2-3 小时 --- ## 🚀 后续优化 完成 schema 统一后,可以考虑: 1. 添加 JSDoc 注释 2. 优化表结构 3. 添加索引优化 4. 实现按模块拆分(方案 B)
未来鸟
2026年7月27日 10:35
转发
收藏文档
上一篇
下一篇
手机扫码
复制链接
手机扫一扫转发分享
复制链接
分享
链接
类型
密码
更新密码
有效期
Markdown文件
Word文件
PDF文档(打印)
AI