fix: 修复CreateN8nTemplatesTable迁移文件类型错误
- 使用TableIndex替代Index类创建数据库索引 - 修复createIndex方法参数类型错误 - 更新dropIndex方法参数格式 - 确保TypeScript类型检查通过
This commit is contained in:
parent
a513202155
commit
ef90c7c71d
|
|
@ -0,0 +1,190 @@
|
|||
import { MigrationInterface, QueryRunner, Table, TableIndex } from 'typeorm';
|
||||
|
||||
export class CreateN8nTemplatesTable1725434673000 implements MigrationInterface {
|
||||
name = 'CreateN8nTemplatesTable1725434673000';
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.createTable(
|
||||
new Table({
|
||||
name: 'n8n_templates',
|
||||
columns: [
|
||||
{
|
||||
name: 'id',
|
||||
type: 'bigint',
|
||||
isPrimary: true,
|
||||
isGenerated: true,
|
||||
generationStrategy: 'increment',
|
||||
comment: '主键ID'
|
||||
},
|
||||
{
|
||||
name: 'code',
|
||||
type: 'varchar',
|
||||
length: '100',
|
||||
isUnique: true,
|
||||
isNullable: false,
|
||||
comment: '模板唯一标识码'
|
||||
},
|
||||
{
|
||||
name: 'name',
|
||||
type: 'varchar',
|
||||
length: '200',
|
||||
isNullable: false,
|
||||
comment: '模板名称'
|
||||
},
|
||||
{
|
||||
name: 'description',
|
||||
type: 'text',
|
||||
isNullable: true,
|
||||
comment: '模板详细描述'
|
||||
},
|
||||
{
|
||||
name: 'credit_cost',
|
||||
type: 'int',
|
||||
default: 0,
|
||||
isNullable: false,
|
||||
comment: '积分消耗'
|
||||
},
|
||||
{
|
||||
name: 'version',
|
||||
type: 'varchar',
|
||||
length: '50',
|
||||
isNullable: false,
|
||||
comment: '版本号'
|
||||
},
|
||||
{
|
||||
name: 'input_example_url',
|
||||
type: 'text',
|
||||
isNullable: true,
|
||||
comment: '输入示例图片'
|
||||
},
|
||||
{
|
||||
name: 'output_example_url',
|
||||
type: 'text',
|
||||
isNullable: true,
|
||||
comment: '输出示例图片'
|
||||
},
|
||||
{
|
||||
name: 'tags',
|
||||
type: 'json',
|
||||
isNullable: true,
|
||||
comment: '标签数组'
|
||||
},
|
||||
{
|
||||
name: 'template_type',
|
||||
type: 'enum',
|
||||
enum: ['image', 'video'],
|
||||
isNullable: false,
|
||||
comment: '模板类型'
|
||||
},
|
||||
{
|
||||
name: 'template_class',
|
||||
type: 'varchar',
|
||||
length: '100',
|
||||
isNullable: false,
|
||||
comment: '具体模板类名'
|
||||
},
|
||||
{
|
||||
name: 'image_model',
|
||||
type: 'varchar',
|
||||
length: '100',
|
||||
isNullable: true,
|
||||
comment: '图片生成模型'
|
||||
},
|
||||
{
|
||||
name: 'image_prompt',
|
||||
type: 'text',
|
||||
isNullable: true,
|
||||
comment: '图片生成提示词'
|
||||
},
|
||||
{
|
||||
name: 'video_model',
|
||||
type: 'varchar',
|
||||
length: '100',
|
||||
isNullable: true,
|
||||
comment: '视频生成模型'
|
||||
},
|
||||
{
|
||||
name: 'video_prompt',
|
||||
type: 'text',
|
||||
isNullable: true,
|
||||
comment: '视频生成提示词'
|
||||
},
|
||||
{
|
||||
name: 'duration',
|
||||
type: 'int',
|
||||
isNullable: true,
|
||||
comment: '视频时长(秒)'
|
||||
},
|
||||
{
|
||||
name: 'aspect_ratio',
|
||||
type: 'varchar',
|
||||
length: '20',
|
||||
isNullable: true,
|
||||
comment: '视频比例'
|
||||
},
|
||||
{
|
||||
name: 'is_active',
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
isNullable: false,
|
||||
comment: '是否启用'
|
||||
},
|
||||
{
|
||||
name: 'sort_order',
|
||||
type: 'int',
|
||||
default: 0,
|
||||
isNullable: false,
|
||||
comment: '排序权重'
|
||||
},
|
||||
{
|
||||
name: 'created_at',
|
||||
type: 'timestamp',
|
||||
default: 'CURRENT_TIMESTAMP',
|
||||
isNullable: false,
|
||||
comment: '创建时间'
|
||||
},
|
||||
{
|
||||
name: 'updated_at',
|
||||
type: 'timestamp',
|
||||
default: 'CURRENT_TIMESTAMP',
|
||||
onUpdate: 'CURRENT_TIMESTAMP',
|
||||
isNullable: false,
|
||||
comment: '更新时间'
|
||||
}
|
||||
]
|
||||
}),
|
||||
true
|
||||
);
|
||||
|
||||
// 创建索引
|
||||
await queryRunner.createIndex('n8n_templates', new TableIndex({
|
||||
name: 'idx_code',
|
||||
columnNames: ['code']
|
||||
}));
|
||||
|
||||
await queryRunner.createIndex('n8n_templates', new TableIndex({
|
||||
name: 'idx_type',
|
||||
columnNames: ['template_type']
|
||||
}));
|
||||
|
||||
await queryRunner.createIndex('n8n_templates', new TableIndex({
|
||||
name: 'idx_class',
|
||||
columnNames: ['template_class']
|
||||
}));
|
||||
|
||||
await queryRunner.createIndex('n8n_templates', new TableIndex({
|
||||
name: 'idx_active',
|
||||
columnNames: ['is_active']
|
||||
}));
|
||||
|
||||
console.log('✅ N8n Templates table created successfully');
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.dropIndex('n8n_templates', 'idx_active');
|
||||
await queryRunner.dropIndex('n8n_templates', 'idx_class');
|
||||
await queryRunner.dropIndex('n8n_templates', 'idx_type');
|
||||
await queryRunner.dropIndex('n8n_templates', 'idx_code');
|
||||
await queryRunner.dropTable('n8n_templates');
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue