Files
competition-website/database/migrations/006-create-work-submissions.js

85 lines
2.0 KiB
JavaScript
Raw Permalink Normal View History

'use strict';
/**
* 迁移文件:创建作品提交表(work_submissions)
* 存储选手上传的作品文件信息
*/
module.exports = {
up: async (queryInterface, Sequelize) => {
const { INTEGER, STRING, DATE } = Sequelize;
await queryInterface.createTable('work_submissions', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
allowNull: false,
comment: '作品提交唯一标识',
},
contestant_id: {
type: INTEGER,
allowNull: false,
comment: '选手 ID',
references: {
model: 'contestants',
key: 'id',
},
onUpdate: 'CASCADE',
onDelete: 'CASCADE',
},
file_type: {
type: STRING(20),
allowNull: false,
comment: '文件类型(plan/ppt)',
},
file_name: {
type: STRING(200),
allowNull: false,
comment: '原始文件名',
},
file_path: {
type: STRING(500),
allowNull: false,
comment: '文件存储路径',
},
file_size: {
type: INTEGER,
allowNull: false,
comment: '文件大小(字节)',
},
submit_time: {
type: DATE,
allowNull: false,
comment: '提交时间',
},
score: {
type: INTEGER,
allowNull: true,
defaultValue: null,
comment: '作品得分',
},
created_at: {
type: DATE,
allowNull: false,
comment: '创建时间',
},
updated_at: {
type: DATE,
allowNull: false,
comment: '更新时间',
},
});
await queryInterface.addIndex('work_submissions', ['contestant_id'], {
name: 'idx_work_submissions_contestant_id',
});
await queryInterface.addIndex('work_submissions', ['file_type'], {
name: 'idx_work_submissions_file_type',
});
},
down: async (queryInterface) => {
await queryInterface.dropTable('work_submissions');
},
};