- 新增模板CRUD操作:创建、更新、删除、管理后台查询接口 - 创建CreateTemplateDto和UpdateTemplateDto用于数据验证 - 修复所有迁移文件的MySQL语法兼容性问题 - 转换PostgreSQL特有语法为MySQL标准语法 - 添加索引创建的重复检查机制
47 lines
2.2 KiB
TypeScript
47 lines
2.2 KiB
TypeScript
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||
|
||
/**
|
||
* 创建模板执行相关枚举和表
|
||
* 记录用户使用AI模板生成内容的完整执行过程
|
||
* 包含执行状态、性能指标、积分消耗和结果数据
|
||
*/
|
||
export class CreateTemplateExecutionTable1725506000000 implements MigrationInterface {
|
||
name = 'CreateTemplateExecutionTable1725506000000';
|
||
|
||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||
// 创建模板执行记录表 - 支持图片和视频两种类型的AI生成任务追踪
|
||
// MySQL 中直接在表字段中定义 ENUM,无需单独创建枚举类型
|
||
await queryRunner.query(`
|
||
CREATE TABLE \`template_executions\` (
|
||
\`id\` INT AUTO_INCREMENT PRIMARY KEY,
|
||
\`templateId\` INT NOT NULL,
|
||
\`userId\` VARCHAR(36) NOT NULL,
|
||
\`platform\` ENUM('wechat_mini', 'alipay_mini', 'baidu_mini', 'toutiao_mini', 'qq_mini', 'kuaishou_mini', 'dingtalk_mini', 'taobao_mini', 'wechat_h5', 'mobile_app') NOT NULL,
|
||
\`type\` ENUM('image', 'video') NOT NULL,
|
||
\`prompt\` TEXT NOT NULL,
|
||
\`inputImageUrl\` VARCHAR(500),
|
||
\`outputUrl\` VARCHAR(500),
|
||
\`thumbnailUrl\` VARCHAR(500),
|
||
\`status\` ENUM('pending', 'processing', 'completed', 'failed', 'cancelled') NOT NULL DEFAULT 'pending',
|
||
\`progress\` INT DEFAULT 0,
|
||
\`errorMessage\` TEXT,
|
||
\`executionResult\` JSON,
|
||
\`creditCost\` INT NOT NULL DEFAULT 0,
|
||
\`creditTransactionId\` VARCHAR(100),
|
||
\`inputParams\` JSON,
|
||
\`executionConfig\` JSON,
|
||
\`startedAt\` TIMESTAMP NULL,
|
||
\`completedAt\` TIMESTAMP NULL,
|
||
\`executionDuration\` INT,
|
||
\`createdAt\` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||
\`updatedAt\` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||
CONSTRAINT \`FK_template_executions_userId\` FOREIGN KEY (\`userId\`) REFERENCES \`users\`(\`id\`) ON DELETE CASCADE
|
||
)
|
||
`);
|
||
}
|
||
|
||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||
await queryRunner.query(`DROP TABLE \`template_executions\``);
|
||
// MySQL 中无需单独删除 ENUM 类型,它们与表一起被删除
|
||
}
|
||
} |