import pg from 'pg';

const DATABASE_URL = 'postgresql://edumanager:EduManager2026!Seguro@150.230.87.131:5432/edumanager';
const pool = new pg.Pool({ connectionString: DATABASE_URL });

async function cleanup() {
  try {
    const { rowCount } = await pool.query(
      `DELETE FROM notas_boletim 
       WHERE prova_id IS NOT NULL AND prova_id NOT IN (SELECT id FROM provas)`
    );
    console.log(`[Sucesso] Limpeza concluída: ${rowCount} registros órfãos de notas removidos!`);
  } catch (error) {
    console.error('[Erro] Falha ao limpar banco de dados:', error);
  } finally {
    await pool.end();
    process.exit();
  }
}

cleanup();
