23 lines
984 B
JavaScript
23 lines
984 B
JavaScript
|
|
const mysql = require('mysql2/promise');
|
||
|
|
(async () => {
|
||
|
|
const c = await mysql.createConnection({
|
||
|
|
host: 'localhost', user: 'root', password: '74191221', database: 'competition_db'
|
||
|
|
});
|
||
|
|
try {
|
||
|
|
await c.query("ALTER TABLE exam_submissions ADD COLUMN word_file_path VARCHAR(500) NULL DEFAULT NULL COMMENT 'Word答案文件路径' AFTER answers");
|
||
|
|
console.log('Added word_file_path');
|
||
|
|
} catch (e) {
|
||
|
|
if (e.code === 'ER_DUP_FIELDNAME') console.log('word_file_path exists');
|
||
|
|
else throw e;
|
||
|
|
}
|
||
|
|
try {
|
||
|
|
await c.query("ALTER TABLE exam_submissions ADD COLUMN word_file_name VARCHAR(255) NULL DEFAULT NULL COMMENT 'Word答案文件名' AFTER word_file_path");
|
||
|
|
console.log('Added word_file_name');
|
||
|
|
} catch (e) {
|
||
|
|
if (e.code === 'ER_DUP_FIELDNAME') console.log('word_file_name exists');
|
||
|
|
else throw e;
|
||
|
|
}
|
||
|
|
const [cols] = await c.query('SHOW COLUMNS FROM exam_submissions');
|
||
|
|
cols.forEach(x => console.log(x.Field, x.Type, x.Null));
|
||
|
|
await c.end();
|
||
|
|
})();
|