34849-vm/includes/marketing_bootstrap.php
2026-07-07 01:55:09 +00:00

37 lines
1.1 KiB
PHP

<?php
// Auto-inicializa pequeños ajustes del esquema de Marketing cuando faltan columnas.
// Así evitamos errores al abrir la pantalla o guardar datos nuevos.
function marketing_ensure_schema(PDO $pdo): void
{
static $attempted = false;
if ($attempted) {
return;
}
$attempted = true;
$checkColumnStmt = $pdo->prepare(
'SELECT COUNT(*) AS c '
. 'FROM information_schema.columns '
. 'WHERE table_schema = DATABASE() AND table_name = ? AND column_name = ?'
);
$checkColumnStmt->execute(['marketing_videos', 'observacion']);
$row = $checkColumnStmt->fetch(PDO::FETCH_ASSOC);
$count = (int)($row['c'] ?? 0);
if ($count === 0) {
$file = __DIR__ . '/../db/migrations/086_add_observacion_to_marketing_videos.sql';
if (!is_file($file)) {
throw new RuntimeException('No se encontró la migración: ' . basename($file));
}
$sql = file_get_contents($file);
if ($sql === false) {
throw new RuntimeException('No se pudo leer la migración: ' . basename($file));
}
$pdo->exec($sql);
}
}