const { sequelize, Order, OrderItem } = require('../models');

const revertHistory = async () => {
    try {
        console.log("Reverting all orders to TODAY (Jan 2026)...");

        const now = new Date(); // Current time

        // Update all orders to now
        await sequelize.query(
            `UPDATE orders SET created_at = :date`,
            {
                replacements: { date: now },
                type: sequelize.QueryTypes.UPDATE
            }
        );

        // Update all order items to now
        await sequelize.query(
            `UPDATE order_items SET created_at = :date`,
            {
                replacements: { date: now },
                type: sequelize.QueryTypes.UPDATE
            }
        );

        console.log("History reverted! All transactions are now in the current month.");
        console.log("Trend comparison should now be vs 0 (showing +100%).");

    } catch (error) {
        console.error("Error reverting history:", error);
    } finally {
        await sequelize.close();
    }
};

revertHistory();
