30 lines
941 B
PHP
30 lines
941 B
PHP
<?php
|
|
require_once __DIR__ . '/config.php';
|
|
|
|
$pdo = db();
|
|
|
|
try {
|
|
// Add slug column to modifiers table if it doesn't exist
|
|
$pdo->exec("ALTER TABLE modifiers ADD COLUMN slug VARCHAR(100) AFTER name");
|
|
echo "Column 'slug' added to 'modifiers' table.\n";
|
|
|
|
// Populate initial slugs based on names
|
|
$stmt = $pdo->query("SELECT id, name FROM modifiers");
|
|
$modifiers = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
$updateStmt = $pdo->prepare("UPDATE modifiers SET slug = ? WHERE id = ?");
|
|
foreach ($modifiers as $m) {
|
|
$slug = strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '_', $m['name'])));
|
|
$updateStmt->execute([$slug, $m['id']]);
|
|
}
|
|
echo "Initial slugs populated for 'modifiers' table.\n";
|
|
|
|
} catch (PDOException $e) {
|
|
if ($e->getCode() == '42S21') {
|
|
echo "Column 'slug' already exists in 'modifiers' table.\n";
|
|
} else {
|
|
echo "Error: " . $e->getMessage() . "\n";
|
|
}
|
|
}
|
|
|