新增普拉提训练系统的数据库结构和数据导入功能

- 创建普拉提分类和动作数据的SQL导入脚本,支持垫上普拉提和器械普拉提的分类管理
- 实现数据库结构迁移脚本,添加新字段以支持普拉提类型和器械名称
- 更新数据库升级总结文档,详细说明数据库结构变更和数据导入步骤
- 创建训练会话相关表,支持每日训练实例功能
- 引入训练会话管理模块,整合训练计划与实际训练会话的关系
This commit is contained in:
richarjiang
2025-08-15 15:34:11 +08:00
parent bea71af5d3
commit 0edcfdcae9
28 changed files with 2528 additions and 164 deletions

View File

@@ -0,0 +1,79 @@
import { Column, DataType, ForeignKey, Model, PrimaryKey, Table, BelongsTo, HasMany } from 'sequelize-typescript';
import { TrainingPlan } from '../../training-plans/models/training-plan.model';
import { WorkoutExercise } from './workout-exercise.model';
export type WorkoutStatus = 'planned' | 'in_progress' | 'completed' | 'skipped';
@Table({
tableName: 't_workout_sessions',
underscored: true,
})
export class WorkoutSession extends Model {
@PrimaryKey
@Column({
type: DataType.UUID,
defaultValue: DataType.UUIDV4,
})
declare id: string;
@Column({ type: DataType.STRING, allowNull: false })
declare userId: string;
@ForeignKey(() => TrainingPlan)
@Column({ type: DataType.UUID, allowNull: false, comment: '关联的训练计划模板' })
declare trainingPlanId: string;
@BelongsTo(() => TrainingPlan)
declare trainingPlan: TrainingPlan;
@HasMany(() => WorkoutExercise)
declare exercises: WorkoutExercise[];
@Column({ type: DataType.STRING, allowNull: false, comment: '训练会话名称' })
declare name: string;
@Column({ type: DataType.DATE, allowNull: false, comment: '计划训练日期' })
declare scheduledDate: Date;
@Column({ type: DataType.DATE, allowNull: true, comment: '实际开始时间' })
declare startedAt: Date;
@Column({ type: DataType.DATE, allowNull: true, comment: '实际结束时间' })
declare completedAt: Date;
@Column({
type: DataType.ENUM('planned', 'in_progress', 'completed', 'skipped'),
allowNull: false,
defaultValue: 'planned',
comment: '训练状态'
})
declare status: WorkoutStatus;
@Column({ type: DataType.INTEGER, allowNull: true, comment: '总时长(秒)' })
declare totalDurationSec: number;
@Column({ type: DataType.TEXT, allowNull: true, comment: '训练总结/备注' })
declare summary: string;
@Column({ type: DataType.INTEGER, allowNull: true, comment: '消耗卡路里(估算)' })
declare caloriesBurned: number;
@Column({ type: DataType.JSON, allowNull: true, comment: '训练统计数据' })
declare stats: {
totalExercises?: number;
completedExercises?: number;
totalSets?: number;
completedSets?: number;
totalReps?: number;
completedReps?: number;
};
@Column({ type: DataType.DATE, defaultValue: DataType.NOW })
declare createdAt: Date;
@Column({ type: DataType.DATE, defaultValue: DataType.NOW })
declare updatedAt: Date;
@Column({ type: DataType.BOOLEAN, defaultValue: false, comment: '是否已删除' })
declare deleted: boolean;
}