require('dotenv').config({ path: '/root/Apps/Camila/.env' }); const { Pool } = require('pg'); const pool = new Pool({ connectionString: process.env.DATABASE_URL }); async function migrate() { try { console.log("Conectando ao banco..."); const cols = await pool.query(` SELECT column_name FROM information_schema.columns WHERE table_schema='escola' AND table_name='config'; `); const colNames = cols.rows.map(r => r.column_name); console.log("Colunas atuais:", colNames); if (colNames.includes('kemily_avatar_url')) { console.log("Renomeando kemily_avatar_url -> ia_avatar_url"); await pool.query(`ALTER TABLE escola.config RENAME COLUMN kemily_avatar_url TO ia_avatar_url;`); } if (colNames.includes('camila_avatar_url')) { console.log("Renomeando camila_avatar_url -> user_avatar_url"); await pool.query(`ALTER TABLE escola.config RENAME COLUMN camila_avatar_url TO user_avatar_url;`); } await pool.query(`ALTER TABLE escola.config ALTER COLUMN agent_name SET DEFAULT 'PedagogIA';`); await pool.query(`ALTER TABLE escola.config ALTER COLUMN ia_avatar_url SET DEFAULT 'assets/pedagog_ia.png';`); await pool.query(`ALTER TABLE escola.config ALTER COLUMN user_avatar_url SET DEFAULT 'assets/pedagog_user.png';`); await pool.query(`UPDATE escola.config SET agent_name = 'PedagogIA' WHERE agent_name = 'Kemily';`); await pool.query(`UPDATE escola.config SET ia_avatar_url = 'assets/pedagog_ia.png' WHERE ia_avatar_url = 'assets/kemily.png';`); await pool.query(`UPDATE escola.config SET user_avatar_url = 'assets/pedagog_user.png' WHERE user_avatar_url = 'assets/camila_prof.png';`); console.log("Migração concluída com sucesso!"); const updated = await pool.query(`SELECT * FROM escola.config;`); console.log("Configurações atualizadas:", updated.rows); } catch (err) { console.error("Erro na migração:", err); } finally { await pool.end(); } } migrate();