import { MigrationInterface, QueryRunner } from 'typeorm'; /** * 创建模板执行相关枚举和表 * 记录用户使用AI模板生成内容的完整执行过程 * 包含执行状态、性能指标、积分消耗和结果数据 */ export class CreateTemplateExecutionTable1725506000000 implements MigrationInterface { name = 'CreateTemplateExecutionTable1725506000000'; public async up(queryRunner: QueryRunner): Promise { // 创建模板执行记录表 - 支持图片和视频两种类型的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 { await queryRunner.query(`DROP TABLE \`template_executions\``); // MySQL 中无需单独删除 ENUM 类型,它们与表一起被删除 } }