![]() Server : Apache/2 System : Linux server-15-235-50-60 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64 User : gositeme ( 1004) PHP Version : 8.2.29 Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname Directory : /home/gositeme/domains/soundstudiopro.com/public_html/migrations/ |
<?php
/**
* Migration: Add title_user_modified column to music_tracks
*
* This column tracks whether a user has explicitly modified the track title.
* When true, auto-fix scripts and callbacks will NOT overwrite the title.
*
* Run once: https://soundstudiopro.com/migrations/add_title_user_modified_column.php
*/
require_once dirname(__DIR__) . '/config/database.php';
echo "<h1>Migration: Add title_user_modified Column</h1>";
try {
$pdo = getDBConnection();
// Check if column already exists
$stmt = $pdo->query("SHOW COLUMNS FROM music_tracks LIKE 'title_user_modified'");
$exists = $stmt->fetch();
if ($exists) {
echo "<p style='color: orange;'>⚠️ Column 'title_user_modified' already exists. No changes made.</p>";
} else {
// Add the column
$pdo->exec("
ALTER TABLE music_tracks
ADD COLUMN title_user_modified TINYINT(1) NOT NULL DEFAULT 0
COMMENT 'Set to 1 when user explicitly edits title, prevents auto-overwrite'
AFTER title
");
echo "<p style='color: green;'>✅ Column 'title_user_modified' added successfully!</p>";
// Set flag for tracks that already have non-default titles
// (Assumes if title exists and isn't default, user may have set it)
$result = $pdo->exec("
UPDATE music_tracks
SET title_user_modified = 1
WHERE title IS NOT NULL
AND title != ''
AND title != 'Untitled Track'
AND title != 'Generated Track'
AND status = 'complete'
");
echo "<p style='color: green;'>✅ Set title_user_modified=1 for $result existing tracks with custom titles.</p>";
}
// Show current stats
$stmt = $pdo->query("
SELECT
COUNT(*) as total,
SUM(CASE WHEN title_user_modified = 1 THEN 1 ELSE 0 END) as user_modified,
SUM(CASE WHEN title_user_modified = 0 THEN 1 ELSE 0 END) as auto_managed
FROM music_tracks
");
$stats = $stmt->fetch(PDO::FETCH_ASSOC);
echo "<h2>Current Stats</h2>";
echo "<p>Total tracks: {$stats['total']}</p>";
echo "<p>User-modified titles (protected): {$stats['user_modified']}</p>";
echo "<p>Auto-managed titles: {$stats['auto_managed']}</p>";
echo "<h2>✅ Migration Complete</h2>";
} catch (Exception $e) {
echo "<p style='color: red;'>❌ Error: " . htmlspecialchars($e->getMessage()) . "</p>";
}
?>