Files
sena_db_api_layer/migration_scripts/migrate-status-6-to-5.js
vuongps38770 72283443ab
All checks were successful
Deploy to Production / deploy (push) Successful in 20s
update
2026-02-28 20:00:38 +07:00

35 lines
1018 B
JavaScript

const { Context } = require('../models');
const { Op } = require('sequelize');
const { sequelize } = require('../config/database');
async function migrate() {
try {
await sequelize.authenticate();
console.log('✅ Kết nối database thành công.');
const fromDate = new Date('2026-02-28T09:00:00Z');
console.log(`🔍 Tìm kiếm các context có status = 6 và update từ ${fromDate.toISOString()} trở đi...`);
const [affectedCount] = await Context.update(
{ status: 5 },
{
where: {
status: 6,
updated_at: {
[Op.gte]: fromDate
}
}
}
);
console.log(`✅ Đã cập nhật thành công ${affectedCount} bản ghi từ status 6 sang status 5.`);
process.exit(0);
} catch (error) {
console.error('❌ Lỗi khi migration:', error);
process.exit(1);
}
}
migrate();