Dev#365
Merged
fastapiadmin merged 5 commits intomasterfrom Apr 20, 2026
Merged
Conversation
## 背景 本次修复包含前后端两部分: 1. 前端SQL模板添加软删除字段(新功能) 2. 后端代码模板排除软删除字段(预防性修复) ## 修复内容 ### 前端模板:添加软删除字段(新功能) **文件**: createTableVisualPresets.ts 之前前端SQL模板缺少软删除字段,导致生成的表不完整。 - **mixinMysql()**: 添加软删除字段 - is_deleted: tinyint(1) NOT NULL - 标记是否已删除 - deleted_time: datetime NULL - 记录删除时间 - deleted_id: int NULL - 记录删除人ID - **mixinPostgres()**: 添加软删除字段 - is_deleted: boolean NOT NULL - 标记是否已删除 - deleted_time: timestamp without time zone NULL - 记录删除时间 - deleted_id: integer NULL - 记录删除人ID ### 后端模板:排除软删除字段(预防性修复) **文件**: model.py.j2, schema.py.j2 虽然之前前端模板没有软删除字段,但为了配合前端修复,需要确保后端模板正确排除这些字段。 - **model.py.j2**: 在排除列表中添加 is_deleted, deleted_time, deleted_id - 原排除列表: ['id', 'uuid', 'status', 'description', 'created_time', 'updated_time', 'created_id', 'updated_id'] - 新排除列表: 添加 'is_deleted', 'deleted_time', 'deleted_id' - 原因: 这些字段由 ModelMixin 和 UserMixin 提供,不应在生成的模型中重复定义 - **schema.py.j2**: 在排除列表中添加 is_deleted, deleted_time, deleted_id - 原排除列表: ['uuid', 'created_time', 'updated_time', 'created_id', 'updated_id'] - 新排除列表: 添加 'is_deleted', 'deleted_time', 'deleted_id' - 原因: 软删除字段由系统自动管理,不应出现在新增/更新Schema中 ## 技术说明 ### 软删除机制 软删除(逻辑删除)是一种不物理删除数据的删除方式: - **is_deleted**: 标记记录是否已删除(false=未删除, true=已删除) - **deleted_time**: 记录删除时间,用于审计和数据恢复 - **deleted_id**: 记录删除操作人ID,外键关联sys_user表 ### 字段继承关系 生成的模型继承自两个基类: - **ModelMixin**: 提供 id, uuid, status, description, created_time, updated_time, is_deleted, deleted_time - **UserMixin**: 提供 created_id, updated_id, deleted_id 及对应的关联关系 代码生成器应排除这些字段,避免重复定义。 ## 修复效果 ### 修复前 - 前端模板生成的表缺少软删除字段 ❌ - 后端模板排除列表不完整(虽然暂时没问题,因为前端也没生成这些字段) ### 修复后 - 前端模板生成的表包含完整的软删除字段 ✅ - 后端模板正确排除软删除字段,避免重复定义 ✅ - 前后端配合,生成的代码正确继承基类的软删除功能 ✅ ## 影响范围 - ✅ 使用\"单表·MySQL\"或\"单表·PostgreSQL\"模板创建的表自动包含软删除字段 - ✅ 生成的model.py只包含业务字段,不会重复定义基础字段 - ✅ 所有新生成的模型自动支持软删除功能 - ✅ 与现有系统的软删除机制保持一致"
- EnhancedDialog 新增 fullscreen-change 事件,用于监听全屏状态变化 - GenColumnsStep 表格高度改为动态计算,适配不同屏幕尺寸 - ImportDbTableDialog 支持全屏模式,表格高度根据全屏状态自动调整 - 优化表格高度计算逻辑,确保内容区域合理利用屏幕空间
- 新增 run.sh 交互式管理脚本,提供以下功能: - 启动开发服务器(自动检查并创建数据库) - 生成和应用数据库迁移 - 重置迁移记录 - 清理和删除数据库 - 执行 SQL 初始化脚本 - 支持从 .env.dev 文件读取数据库配置 - 提供彩色输出和友好的交互界面 - 包含安全确认机制防止误操作
问题:
- 同步数据库接口 /api/v1/generator/gencode/sync_db/{table_name} 报错
- 错误信息:'super_column' is an invalid keyword argument for GenTableColumnModel
原因:
- GenTableColumnOutSchema 包含 super_column 输出字段
- GenTableColumnModel 数据库模型不包含此字段
- 同步时直接使用 OutSchema 对象创建/更新数据库记录导致参数错误
解决方案:
- 在创建/更新数据库记录前,将 GenTableColumnOutSchema 转换为 GenTableColumnSchema
- 使用 model_dump(exclude={"super_column"}) 排除输出专用字段
- 确保传递给 CRUD 层的数据只包含数据库模型支持的字段
移除不再使用的搜索功能,包括工具栏中的搜索按钮、搜索区域切换按钮及相关事件处理逻辑。 同时更新模板文件和相关配置,确保代码一致性。 调整页面布局样式,优化执行日志抽屉的显示效果。 在代码生成器中添加保存按钮,允许在配置过程中保存当前进度。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.