refactor: 上传/下载接口全面迁移到统一 files 表,移除 attachments 模型

- 删除 models/attachment.go,Attachment 模型由 File(Type=attachments)替代
- handlers/attachment.go:上传/删除/列表/绑定全部改读写 files 表,
  查询按 type='attachments' 过滤(为 avatar/logo 等类型预留隔离)
- models/db.go:AutoMigrate 移除 Attachment;启动迁移仅当旧表仍存在时执行
  (升级路径保障,已删除则为无操作)
- 测试同步切换到 File 模型(security_test/bodylimit_test)
- scripts/drop_attachments_table.sql:旧表删除脚本(含前置校验说明)
This commit is contained in:
dsh
2026-08-28 19:23:50 +08:00
parent 09bf35d0dd
commit 970dbd4c5b
7 changed files with 62 additions and 75 deletions
+11
View File
@@ -0,0 +1,11 @@
-- Migration: 删除旧 attachments 表(数据已迁移至统一 files 表,type='attachments'
-- Date: 2026-08-28
-- 前置条件:已部署使用 files 表的新版 blog_go 并完成验证(启动迁移会把
-- 尚未搬运的 attachments 行复制进 files)。本脚本幂等,可安全重跑。
--
-- 执行前确认:
-- SELECT COUNT(*) AS remaining FROM attachments a
-- WHERE NOT EXISTS (SELECT 1 FROM files f WHERE f.id = a.id);
-- 结果应为 0——若有遗留行,先重启新版本服务让其自动搬运。
DROP TABLE IF EXISTS `attachments`;