import { pool } from "./config/db.js";

async function migrate() {
  console.log("Adding reset_token columns to users table...");
  try {
    const [columns] = await pool.query("SHOW COLUMNS FROM users");
    const fields = columns.map(c => c.Field);

    if (!fields.includes("reset_token")) {
      await pool.query("ALTER TABLE users ADD COLUMN reset_token VARCHAR(64) DEFAULT NULL");
      console.log("Added reset_token column.");
    }
    if (!fields.includes("reset_token_expires")) {
      await pool.query("ALTER TABLE users ADD COLUMN reset_token_expires DATETIME DEFAULT NULL");
      console.log("Added reset_token_expires column.");
    }

    console.log("Migration complete!");
    process.exit(0);
  } catch (err) {
    console.error("Migration failed:", err);
    process.exit(1);
  }
}

migrate();
