This commit is contained in:
34
migration_scripts/migrate-status-6-to-5.js
Normal file
34
migration_scripts/migrate-status-6-to-5.js
Normal file
@@ -0,0 +1,34 @@
|
||||
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();
|
||||
Reference in New Issue
Block a user