fix(db): separar ejecucion DDL en PostgreSQL para asegurar creacion de push_subscriptions

This commit is contained in:
unknown
2026-10-06 02:06:41 -06:00
parent bedcbf27a6
commit a1b3d5d72c
+13 -1
View File
@@ -116,11 +116,19 @@ function initDatabase() {
activo BOOLEAN DEFAULT TRUE, activo BOOLEAN DEFAULT TRUE,
creado_en TIMESTAMP DEFAULT CURRENT_TIMESTAMP creado_en TIMESTAMP DEFAULT CURRENT_TIMESTAMP
); );
`);
} catch (e) {}
try {
db.exec(`
INSERT INTO escuelas (id, codigo, nombre, telefono_sinpe, nombre_sinpe, concesionario, activo) INSERT INTO escuelas (id, codigo, nombre, telefono_sinpe, nombre_sinpe, concesionario, activo)
VALUES (1, 'ESC01', 'Soda Escolar Central', '8888-8888', 'Soda Central', 'Concesionario Central', true) VALUES (1, 'ESC01', 'Soda Escolar Central', '8888-8888', 'Soda Central', 'Concesionario Central', true)
ON CONFLICT (id) DO NOTHING; ON CONFLICT (id) DO NOTHING;
`);
} catch (e) {}
try {
db.exec(`
CREATE TABLE IF NOT EXISTS solicitudes_recarga_sinpe ( CREATE TABLE IF NOT EXISTS solicitudes_recarga_sinpe (
id SERIAL PRIMARY KEY, id SERIAL PRIMARY KEY,
estudiante_id INTEGER NOT NULL REFERENCES estudiantes(id) ON DELETE CASCADE, estudiante_id INTEGER NOT NULL REFERENCES estudiantes(id) ON DELETE CASCADE,
@@ -134,7 +142,11 @@ function initDatabase() {
creado_en TIMESTAMP DEFAULT CURRENT_TIMESTAMP, creado_en TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
procesado_en TIMESTAMP procesado_en TIMESTAMP
); );
`);
} catch (e) {}
try {
db.exec(`
CREATE TABLE IF NOT EXISTS push_subscriptions ( CREATE TABLE IF NOT EXISTS push_subscriptions (
id SERIAL PRIMARY KEY, id SERIAL PRIMARY KEY,
endpoint TEXT UNIQUE NOT NULL, endpoint TEXT UNIQUE NOT NULL,
@@ -147,7 +159,7 @@ function initDatabase() {
); );
`); `);
} catch (e) { } catch (e) {
console.error('Error creando tablas en PostgreSQL:', e); console.error('Error creando push_subscriptions en PostgreSQL:', e);
} }
seedUsuarios(); seedUsuarios();
seedDisenosTarjetas(); seedDisenosTarjetas();