import mysql from "mysql2/promise"; const dbUrl = process.env.DATABASE_URL; if (!dbUrl) { console.error("DATABASE_URL not set"); process.exit(1); } // Parse DATABASE_URL: mysql://user:password@host:port/database const url = new URL(dbUrl.replace("mysql://", "mysql+srv://")); const [user, password] = url.username && url.password ? [url.username, url.password] : ["root", ""]; const host = url.hostname; const port = url.port || 4000; const database = url.pathname.slice(1); const connection = await mysql.createConnection({ host, port: parseInt(port), user, password, database, ssl: {}, enableKeepAlive: true, }); try { // Update user role to admin const [result] = await connection.execute( "UPDATE users SET role = ? WHERE username = ?", ["admin", "coinkrazy26@gmail.com"] ); console.log(`Updated ${result.affectedRows} user(s) to admin role`); // Verify the update const [users] = await connection.execute( "SELECT id, username, email, role FROM users WHERE username = ?", ["coinkrazy26@gmail.com"] ); if (users.length > 0) { console.log("Admin account details:"); console.log(users[0]); } process.exit(0); } catch (error) { console.error("Error promoting user to admin:", error.message); process.exit(1); } finally { await connection.end(); }