'use strict'; /** * 导出任务表(全局任务池):提交即落「待处理」任务,定时任务逐个处理并生成 CSV。 * 状态:0待处理 1处理中 2已完成 3失败;文件按 年/月/日 分目录存储。 */ module.exports = { async up(queryInterface, Sequelize) { await queryInterface.createTable( 'export_tasks', { id: { type: Sequelize.BIGINT.UNSIGNED, allowNull: false, autoIncrement: true, primaryKey: true, }, principal_id: { type: Sequelize.BIGINT.UNSIGNED, allowNull: false, comment: '所属主体ID' }, type: { type: Sequelize.STRING(20), allowNull: false, comment: '导出类型:stock_record/product/order' }, status: { type: Sequelize.TINYINT.UNSIGNED, allowNull: false, defaultValue: 0, comment: '0待处理 1处理中 2已完成 3失败' }, sql: { type: Sequelize.TEXT, comment: '实际执行的 MySQL 查询语句(? 占位参数)' }, params: { type: Sequelize.TEXT, comment: '筛选参数 JSON' }, file_path: { type: Sequelize.STRING(255), comment: '相对上传根目录的文件路径' }, file_name: { type: Sequelize.STRING(255), comment: '文件名' }, total_count: { type: Sequelize.INTEGER.UNSIGNED, defaultValue: 0, comment: '总行数' }, processed_count: { type: Sequelize.INTEGER.UNSIGNED, defaultValue: 0, comment: '已处理行数' }, progress: { type: Sequelize.TINYINT.UNSIGNED, defaultValue: 0, comment: '进度百分比' }, error_message: { type: Sequelize.STRING(500), comment: '失败原因' }, created_by: { type: Sequelize.BIGINT.UNSIGNED, comment: '提交人ID' }, created_at: { type: Sequelize.DATE, allowNull: false, defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'), }, updated_at: { type: Sequelize.DATE, allowNull: false, defaultValue: Sequelize.literal('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'), }, }, { charset: 'utf8mb4', collate: 'utf8mb4_unicode_ci', comment: '导出任务(全局任务池)表' } ); await queryInterface.addIndex('export_tasks', { fields: [ 'principal_id' ], name: 'idx_et_principal' }); await queryInterface.addIndex('export_tasks', { fields: [ 'status' ], name: 'idx_et_status' }); await queryInterface.addIndex('export_tasks', { fields: [ 'created_at' ], name: 'idx_et_created' }); }, async down(queryInterface) { await queryInterface.dropTable('export_tasks'); }, };