From 6680202b116654246c7d82dbb96065e27a76dad6 Mon Sep 17 00:00:00 2001 From: Sidney Date: Mon, 25 May 2026 17:58:25 -0300 Subject: [PATCH] feat(sync): add temporary endpoint to fix missing student data migration --- manager/server.selfhosted.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/manager/server.selfhosted.js b/manager/server.selfhosted.js index 12cb6cf..1448b90 100644 --- a/manager/server.selfhosted.js +++ b/manager/server.selfhosted.js @@ -492,6 +492,34 @@ app.delete('/api/disciplinas/:id', async (req, res) => { // ============================================================ // ROTAS DE ALUNOS (MIGRAÇÃO FASE 4) // ============================================================ +app.get('/api/fix-alunos-migracao', async (req, res) => { + try { + const result = await pool.query(` + UPDATE alunos a + SET + data_nascimento = NULLIF(s.elem->>'data_nascimento', '')::timestamp, + rg = s.elem->>'rg', + rua = s.elem->>'rua', + numero = s.elem->>'numero', + bairro = s.elem->>'bairro', + cidade = s.elem->>'cidade', + estado = s.elem->>'estado', + cep = s.elem->>'cep' + FROM ( + SELECT jsonb_array_elements(data->'students') as elem + FROM school_data + WHERE id = 1 + ) s + WHERE a.id = s.elem->>'id' + RETURNING a.nome; + `); + res.json({ success: true, message: `Foram atualizados ${result.rowCount} alunos com os dados do JSON original!` }); + } catch (error) { + console.error(error); + res.status(500).json({ error: error.message }); + } +}); + app.get('/api/alunos', async (req, res) => { try { const alunos = await getAlunos();