Files
yinghuoapi/backend/migrations/migrations.go
yangjianbo 3d617de577 refactor(数据库): 迁移持久层到 Ent 并清理 GORM
将仓储层/基础设施改为 Ent + 原生 SQL 执行路径,并移除 AutoMigrate 与 GORM 依赖。
重构内容包括:
- 仓储层改用 Ent/SQL(含 usage_log/account 等复杂查询),统一错误映射
- 基础设施与 setup 初始化切换为 Ent + SQL migrations
- 集成测试与 fixtures 迁移到 Ent 事务模型
- 清理遗留 GORM 模型/依赖,补充迁移与文档说明
- 增加根目录 Makefile 便于前后端编译

测试:
- go test -tags unit ./...
- go test -tags integration ./...
2025-12-29 10:03:27 +08:00

35 lines
1.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Package migrations 包含嵌入的 SQL 数据库迁移文件。
//
// 该包使用 Go 1.16+ 的 embed 功能将 SQL 文件嵌入到编译后的二进制文件中。
// 这种方式的优点:
// - 部署时无需额外的迁移文件
// - 迁移文件与代码版本一致
// - 便于版本控制和代码审查
package migrations
import "embed"
// FS 包含本目录下所有嵌入的 SQL 迁移文件。
//
// 迁移命名规范:
// - 使用零填充的数字前缀确保正确的执行顺序
// - 格式NNN_description.sql如 001_init.sql, 002_add_users.sql
// - 描述部分使用下划线分隔的小写单词
//
// 迁移文件要求:
// - 必须是幂等的(可重复执行而不产生错误)
// - 推荐使用 IF NOT EXISTS / IF EXISTS 语法
// - 一旦应用,不应修改已有的迁移文件(通过 checksum 校验)
//
// 示例迁移文件:
//
// -- 001_init.sql
// CREATE TABLE IF NOT EXISTS users (
// id BIGSERIAL PRIMARY KEY,
// email VARCHAR(255) NOT NULL UNIQUE,
// created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
// );
//
//go:embed *.sql
var FS embed.FS