fix: remoção de constraints restritivas e melhoria de logs de submissão
This commit is contained in:
parent
0e9a809cd7
commit
dffc7b8903
|
|
@ -0,0 +1,29 @@
|
|||
|
||||
import pkg from 'pg';
|
||||
const { Pool } = pkg;
|
||||
|
||||
const DATABASE_URL = 'postgresql://edumanager:EduManager2026!Seguro@localhost:5432/edumanager';
|
||||
const pool = new Pool({
|
||||
connectionString: DATABASE_URL
|
||||
});
|
||||
|
||||
async function test() {
|
||||
try {
|
||||
console.log('--- TESTANDO INTEGRIDADE ---');
|
||||
const { rows: countAlunos } = await pool.query('SELECT COUNT(*) FROM alunos');
|
||||
console.log('Total em alunos:', countAlunos[0].count);
|
||||
|
||||
const { rows: countProvas } = await pool.query('SELECT COUNT(*) FROM provas');
|
||||
console.log('Total em provas:', countProvas[0].count);
|
||||
|
||||
const { rows: countSub } = await pool.query('SELECT COUNT(*) FROM provas_submissoes');
|
||||
console.log('Total em provas_submissoes:', countSub[0].count);
|
||||
|
||||
} catch (err) {
|
||||
console.error('ERRO NO TESTE:', err.message);
|
||||
} finally {
|
||||
await pool.end();
|
||||
}
|
||||
}
|
||||
|
||||
test();
|
||||
|
|
@ -208,6 +208,16 @@ export async function insertSubmissao(submission) {
|
|||
// HELPERS: notas_boletim
|
||||
// ============================================================
|
||||
export async function initNotasTable() {
|
||||
// Remover constraints restritivas da tabela de submissões se existirem (transição JSON -> Postgres)
|
||||
try {
|
||||
await pool.query(`
|
||||
ALTER TABLE provas_submissoes DROP CONSTRAINT IF EXISTS provas_submissoes_aluno_id_fkey;
|
||||
ALTER TABLE provas_submissoes DROP CONSTRAINT IF EXISTS provas_submissoes_prova_id_fkey;
|
||||
`);
|
||||
} catch (err) {
|
||||
console.log('[PostgreSQL] ℹ️ Submissoes fkey já removidas ou tabela não existe.');
|
||||
}
|
||||
|
||||
await pool.query(`
|
||||
CREATE TABLE IF NOT EXISTS notas_boletim (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
|
|
|
|||
|
|
@ -598,8 +598,12 @@ app.post('/api/portal/avaliacoes/submeter', authMiddleware, async (req, res) =>
|
|||
|
||||
res.json({ success: true, result: { total_questions: totalQuestions, correct_count: correctCount, wrong_count: wrongCount, percentage, final_score: finalScore } });
|
||||
} catch (err) {
|
||||
console.error('Submissao error:', err);
|
||||
res.status(500).json({ error: 'Erro interno.' });
|
||||
console.error('❌ [Portal:Submissão] Erro crítico ao salvar:', err.message, err.stack);
|
||||
res.status(500).json({
|
||||
error: 'Erro interno ao processar nota',
|
||||
details: err.message,
|
||||
code: 'DB_SAVE_ERROR'
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -378,8 +378,8 @@ CREATE TABLE IF NOT EXISTS questoes_provas (
|
|||
-- ============================================================
|
||||
CREATE TABLE IF NOT EXISTS provas_submissoes (
|
||||
id TEXT PRIMARY KEY DEFAULT uuid_generate_v4()::TEXT,
|
||||
aluno_id TEXT NOT NULL REFERENCES alunos(id) ON DELETE CASCADE,
|
||||
prova_id TEXT NOT NULL REFERENCES provas(id) ON DELETE CASCADE,
|
||||
aluno_id TEXT NOT NULL,
|
||||
prova_id TEXT NOT NULL,
|
||||
total_questoes INTEGER DEFAULT 0,
|
||||
acertos INTEGER DEFAULT 0,
|
||||
erros INTEGER DEFAULT 0,
|
||||
|
|
|
|||
Loading…
Reference in New Issue