edumanagerpro2/manager/scratch/update_vagas_and_default_fi...

41 lines
1.4 KiB
JavaScript

const { Pool } = require('pg');
const pool = new Pool({
connectionString: 'postgresql://edumanager:EduManager2026!Seguro@150.230.87.131:5432/edumanager'
});
async function run() {
const client = await pool.connect();
try {
await client.query('BEGIN');
// 1. Add vagas_prematricula to turmas
await client.query(`
ALTER TABLE turmas ADD COLUMN IF NOT EXISTS vagas_prematricula INTEGER DEFAULT NULL;
`);
console.log('✅ Coluna vagas_prematricula adicionada à tabela turmas!');
// 2. Insert default fields in prematricula_campos
await client.query(`
INSERT INTO prematricula_campos (id, label, tipo, placeholder, obrigatorio, opcoes, ordem, ativo)
VALUES
('_nome', 'Nome Completo', 'text', 'Seu nome completo', true, '{}', 10, true),
('_email', 'Email', 'email', 'seu@email.com', false, '{}', 20, true),
('_telefone', 'Telefone / WhatsApp', 'phone', '(00) 00000-0000', false, '{}', 30, true),
('_turma', 'Turma de Interesse', 'select', 'Selecione a turma...', true, '{}', 40, true)
ON CONFLICT (id) DO NOTHING;
`);
console.log('✅ Campos padrão inseridos na tabela prematricula_campos!');
await client.query('COMMIT');
} catch (e) {
await client.query('ROLLBACK');
console.error('❌ Erro na migração:', e.message);
} finally {
client.release();
await pool.end();
}
}
run();