sql: seed directo para módulo Integraciones en producción

This commit is contained in:
Lizandro Guarnizo
2026-05-01 11:00:08 -05:00
parent 6cd52eb085
commit 40e5df9f4e
+56
View File
@@ -0,0 +1,56 @@
-- ============================================================
-- Seed: módulo Integraciones (Hostinger + Cloudflare)
-- Ejecutar en la base de datos PostgreSQL de producción:
-- psql -h HOST -U usite -d usite -f seed_integraciones.sql
-- ============================================================
BEGIN;
-- 1. Insertar módulo "Integraciones" si no existe
INSERT INTO modules (title, description, modified_at, created_at, updated_at)
SELECT 'Integraciones', 'Conexión con servicios externos: Hostinger, Cloudflare y más', NOW(), NOW(), NOW()
WHERE NOT EXISTS (
SELECT 1 FROM modules WHERE title = 'Integraciones' AND deleted_at IS NULL
);
-- 2. Insertar submódulo Hostinger si no existe
INSERT INTO submodules (title, description, url, module_id, modified_at, created_at, updated_at)
SELECT 'Hostinger',
'Panel de VPS, dominios, hosting y DNS de Hostinger',
'/app/hostinger',
(SELECT id FROM modules WHERE title = 'Integraciones' AND deleted_at IS NULL LIMIT 1),
NOW(), NOW(), NOW()
WHERE NOT EXISTS (
SELECT 1 FROM submodules WHERE url = '/app/hostinger' AND deleted_at IS NULL
);
-- 3. Insertar submódulo Cloudflare si no existe
INSERT INTO submodules (title, description, url, module_id, modified_at, created_at, updated_at)
SELECT 'Cloudflare',
'Gestión de zonas, DNS, SSL y firewall en Cloudflare',
'/app/cloudflare',
(SELECT id FROM modules WHERE title = 'Integraciones' AND deleted_at IS NULL LIMIT 1),
NOW(), NOW(), NOW()
WHERE NOT EXISTS (
SELECT 1 FROM submodules WHERE url = '/app/cloudflare' AND deleted_at IS NULL
);
-- 4. Asignar ambos submódulos a TODOS los roles (ignorar duplicados)
INSERT INTO roles_submodules (role_id, submodule_id)
SELECT r.id, s.id
FROM roles r
CROSS JOIN submodules s
WHERE s.url IN ('/app/hostinger', '/app/cloudflare')
AND r.deleted_at IS NULL
AND s.deleted_at IS NULL
ON CONFLICT DO NOTHING;
COMMIT;
-- Verificación rápida
SELECT m.title AS modulo, s.title AS submodulo, s.url
FROM modules m
JOIN submodules s ON s.module_id = m.id
WHERE m.title = 'Integraciones'
AND m.deleted_at IS NULL
AND s.deleted_at IS NULL;