notifyLock method + logs print.send logs order export methods + docs express model fields SPH/XHS/DW/JD + migration platform_shop_id migration notifyLock docs order export docs
49 lines
1.8 KiB
JavaScript
49 lines
1.8 KiB
JavaScript
'use strict';
|
|
const Sequelize = require('sequelize');
|
|
const args = process.argv.slice(2);
|
|
if (args.length < 2) {
|
|
console.error('USAGE: node script/verify-migration.cjs <migrationName> <tableName> [columnsCommaSeparated]');
|
|
process.exit(2);
|
|
}
|
|
const migrationName = args[0];
|
|
const tableName = args[1];
|
|
const columns = (args[2] || '').split(',').filter(Boolean);
|
|
(async () => {
|
|
try {
|
|
const dbConfigAll = require('../database/config.js');
|
|
const dbConfig = dbConfigAll.production;
|
|
const sequelize = new Sequelize(dbConfig.database, dbConfig.username, dbConfig.password, {
|
|
host: dbConfig.host,
|
|
port: dbConfig.port,
|
|
dialect: dbConfig.dialect || 'mysql',
|
|
logging: false,
|
|
});
|
|
await sequelize.authenticate();
|
|
const [metaRows] = await sequelize.query('SELECT name FROM SequelizeMeta WHERE name = ?', { replacements: [migrationName] });
|
|
const metaExists = metaRows && metaRows.length > 0;
|
|
let columnsResult = null;
|
|
try {
|
|
const [cols] = await sequelize.query(`SHOW FULL COLUMNS FROM \`${tableName}\``);
|
|
columnsResult = {};
|
|
for (const c of cols) {
|
|
columnsResult[c.Field] = { Type: c.Type, Null: c.Null, Comment: c.Comment, Default: c.Default };
|
|
}
|
|
} catch (e) {
|
|
// table may not exist
|
|
}
|
|
const checkColumns = {};
|
|
if (columnsResult) {
|
|
for (const col of columns) {
|
|
checkColumns[col] = !!columnsResult[col];
|
|
}
|
|
}
|
|
const result = { migration: migrationName, migrationRecorded: !!metaExists, table: tableName, columnsExist: checkColumns, rawColumns: columnsResult ? Object.keys(columnsResult) : null };
|
|
console.log(JSON.stringify(result));
|
|
await sequelize.close();
|
|
process.exit(0);
|
|
} catch (e) {
|
|
console.error('VERIFY_ERROR', e && e.message ? e.message : e);
|
|
process.exit(3);
|
|
}
|
|
})();
|