Files
sub2api/backend/ent/usersubscription/usersubscription.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

261 lines
10 KiB
Go

// Code generated by ent, DO NOT EDIT.
package usersubscription
import (
"time"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
)
const (
// Label holds the string label denoting the usersubscription type in the database.
Label = "user_subscription"
// FieldID holds the string denoting the id field in the database.
FieldID = "id"
// FieldCreatedAt holds the string denoting the created_at field in the database.
FieldCreatedAt = "created_at"
// FieldUpdatedAt holds the string denoting the updated_at field in the database.
FieldUpdatedAt = "updated_at"
// FieldUserID holds the string denoting the user_id field in the database.
FieldUserID = "user_id"
// FieldGroupID holds the string denoting the group_id field in the database.
FieldGroupID = "group_id"
// FieldStartsAt holds the string denoting the starts_at field in the database.
FieldStartsAt = "starts_at"
// FieldExpiresAt holds the string denoting the expires_at field in the database.
FieldExpiresAt = "expires_at"
// FieldStatus holds the string denoting the status field in the database.
FieldStatus = "status"
// FieldDailyWindowStart holds the string denoting the daily_window_start field in the database.
FieldDailyWindowStart = "daily_window_start"
// FieldWeeklyWindowStart holds the string denoting the weekly_window_start field in the database.
FieldWeeklyWindowStart = "weekly_window_start"
// FieldMonthlyWindowStart holds the string denoting the monthly_window_start field in the database.
FieldMonthlyWindowStart = "monthly_window_start"
// FieldDailyUsageUsd holds the string denoting the daily_usage_usd field in the database.
FieldDailyUsageUsd = "daily_usage_usd"
// FieldWeeklyUsageUsd holds the string denoting the weekly_usage_usd field in the database.
FieldWeeklyUsageUsd = "weekly_usage_usd"
// FieldMonthlyUsageUsd holds the string denoting the monthly_usage_usd field in the database.
FieldMonthlyUsageUsd = "monthly_usage_usd"
// FieldAssignedBy holds the string denoting the assigned_by field in the database.
FieldAssignedBy = "assigned_by"
// FieldAssignedAt holds the string denoting the assigned_at field in the database.
FieldAssignedAt = "assigned_at"
// FieldNotes holds the string denoting the notes field in the database.
FieldNotes = "notes"
// EdgeUser holds the string denoting the user edge name in mutations.
EdgeUser = "user"
// EdgeGroup holds the string denoting the group edge name in mutations.
EdgeGroup = "group"
// EdgeAssignedByUser holds the string denoting the assigned_by_user edge name in mutations.
EdgeAssignedByUser = "assigned_by_user"
// Table holds the table name of the usersubscription in the database.
Table = "user_subscriptions"
// UserTable is the table that holds the user relation/edge.
UserTable = "user_subscriptions"
// UserInverseTable is the table name for the User entity.
// It exists in this package in order to avoid circular dependency with the "user" package.
UserInverseTable = "users"
// UserColumn is the table column denoting the user relation/edge.
UserColumn = "user_id"
// GroupTable is the table that holds the group relation/edge.
GroupTable = "user_subscriptions"
// GroupInverseTable is the table name for the Group entity.
// It exists in this package in order to avoid circular dependency with the "group" package.
GroupInverseTable = "groups"
// GroupColumn is the table column denoting the group relation/edge.
GroupColumn = "group_id"
// AssignedByUserTable is the table that holds the assigned_by_user relation/edge.
AssignedByUserTable = "user_subscriptions"
// AssignedByUserInverseTable is the table name for the User entity.
// It exists in this package in order to avoid circular dependency with the "user" package.
AssignedByUserInverseTable = "users"
// AssignedByUserColumn is the table column denoting the assigned_by_user relation/edge.
AssignedByUserColumn = "assigned_by"
)
// Columns holds all SQL columns for usersubscription fields.
var Columns = []string{
FieldID,
FieldCreatedAt,
FieldUpdatedAt,
FieldUserID,
FieldGroupID,
FieldStartsAt,
FieldExpiresAt,
FieldStatus,
FieldDailyWindowStart,
FieldWeeklyWindowStart,
FieldMonthlyWindowStart,
FieldDailyUsageUsd,
FieldWeeklyUsageUsd,
FieldMonthlyUsageUsd,
FieldAssignedBy,
FieldAssignedAt,
FieldNotes,
}
// ValidColumn reports if the column name is valid (part of the table columns).
func ValidColumn(column string) bool {
for i := range Columns {
if column == Columns[i] {
return true
}
}
return false
}
var (
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
DefaultCreatedAt func() time.Time
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
DefaultUpdatedAt func() time.Time
// UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field.
UpdateDefaultUpdatedAt func() time.Time
// DefaultStatus holds the default value on creation for the "status" field.
DefaultStatus string
// StatusValidator is a validator for the "status" field. It is called by the builders before save.
StatusValidator func(string) error
// DefaultDailyUsageUsd holds the default value on creation for the "daily_usage_usd" field.
DefaultDailyUsageUsd float64
// DefaultWeeklyUsageUsd holds the default value on creation for the "weekly_usage_usd" field.
DefaultWeeklyUsageUsd float64
// DefaultMonthlyUsageUsd holds the default value on creation for the "monthly_usage_usd" field.
DefaultMonthlyUsageUsd float64
// DefaultAssignedAt holds the default value on creation for the "assigned_at" field.
DefaultAssignedAt func() time.Time
)
// OrderOption defines the ordering options for the UserSubscription queries.
type OrderOption func(*sql.Selector)
// ByID orders the results by the id field.
func ByID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldID, opts...).ToFunc()
}
// ByCreatedAt orders the results by the created_at field.
func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldCreatedAt, opts...).ToFunc()
}
// ByUpdatedAt orders the results by the updated_at field.
func ByUpdatedAt(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldUpdatedAt, opts...).ToFunc()
}
// ByUserID orders the results by the user_id field.
func ByUserID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldUserID, opts...).ToFunc()
}
// ByGroupID orders the results by the group_id field.
func ByGroupID(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldGroupID, opts...).ToFunc()
}
// ByStartsAt orders the results by the starts_at field.
func ByStartsAt(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldStartsAt, opts...).ToFunc()
}
// ByExpiresAt orders the results by the expires_at field.
func ByExpiresAt(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldExpiresAt, opts...).ToFunc()
}
// ByStatus orders the results by the status field.
func ByStatus(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldStatus, opts...).ToFunc()
}
// ByDailyWindowStart orders the results by the daily_window_start field.
func ByDailyWindowStart(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldDailyWindowStart, opts...).ToFunc()
}
// ByWeeklyWindowStart orders the results by the weekly_window_start field.
func ByWeeklyWindowStart(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldWeeklyWindowStart, opts...).ToFunc()
}
// ByMonthlyWindowStart orders the results by the monthly_window_start field.
func ByMonthlyWindowStart(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldMonthlyWindowStart, opts...).ToFunc()
}
// ByDailyUsageUsd orders the results by the daily_usage_usd field.
func ByDailyUsageUsd(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldDailyUsageUsd, opts...).ToFunc()
}
// ByWeeklyUsageUsd orders the results by the weekly_usage_usd field.
func ByWeeklyUsageUsd(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldWeeklyUsageUsd, opts...).ToFunc()
}
// ByMonthlyUsageUsd orders the results by the monthly_usage_usd field.
func ByMonthlyUsageUsd(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldMonthlyUsageUsd, opts...).ToFunc()
}
// ByAssignedBy orders the results by the assigned_by field.
func ByAssignedBy(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldAssignedBy, opts...).ToFunc()
}
// ByAssignedAt orders the results by the assigned_at field.
func ByAssignedAt(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldAssignedAt, opts...).ToFunc()
}
// ByNotes orders the results by the notes field.
func ByNotes(opts ...sql.OrderTermOption) OrderOption {
return sql.OrderByField(FieldNotes, opts...).ToFunc()
}
// ByUserField orders the results by user field.
func ByUserField(field string, opts ...sql.OrderTermOption) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborTerms(s, newUserStep(), sql.OrderByField(field, opts...))
}
}
// ByGroupField orders the results by group field.
func ByGroupField(field string, opts ...sql.OrderTermOption) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborTerms(s, newGroupStep(), sql.OrderByField(field, opts...))
}
}
// ByAssignedByUserField orders the results by assigned_by_user field.
func ByAssignedByUserField(field string, opts ...sql.OrderTermOption) OrderOption {
return func(s *sql.Selector) {
sqlgraph.OrderByNeighborTerms(s, newAssignedByUserStep(), sql.OrderByField(field, opts...))
}
}
func newUserStep() *sqlgraph.Step {
return sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.To(UserInverseTable, FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, UserTable, UserColumn),
)
}
func newGroupStep() *sqlgraph.Step {
return sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.To(GroupInverseTable, FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, GroupTable, GroupColumn),
)
}
func newAssignedByUserStep() *sqlgraph.Step {
return sqlgraph.NewStep(
sqlgraph.From(Table, FieldID),
sqlgraph.To(AssignedByUserInverseTable, FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, AssignedByUserTable, AssignedByUserColumn),
)
}