Fix: Verhindere Fatal Error durch doppelte Spalten-Anlage bei Auto-Migration in index.php
All checks were successful
Docker Build & Push / build-and-push (push) Successful in 39s
All checks were successful
Docker Build & Push / build-and-push (push) Successful in 39s
This commit is contained in:
@@ -14,11 +14,19 @@ if (!isset($_SESSION['user_id'])) {
|
||||
require_once 'db_connect.php';
|
||||
|
||||
// --- AUTO MIGRATIONS ---
|
||||
$conn->query("ALTER TABLE users ADD COLUMN display_name VARCHAR(255) DEFAULT NULL");
|
||||
$check_display_name = $conn->query("SHOW COLUMNS FROM users LIKE 'display_name'");
|
||||
if ($check_display_name && $check_display_name->num_rows == 0) {
|
||||
$conn->query("ALTER TABLE users ADD COLUMN display_name VARCHAR(255) DEFAULT NULL");
|
||||
}
|
||||
|
||||
$conn->query("CREATE TABLE IF NOT EXISTS todo_lists (id INT AUTO_INCREMENT PRIMARY KEY, user_id INT NOT NULL, household_id INT DEFAULT NULL, name VARCHAR(255) NOT NULL, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE, FOREIGN KEY (household_id) REFERENCES households(id) ON DELETE CASCADE) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci");
|
||||
$conn->query("CREATE TABLE IF NOT EXISTS todo_items (id INT AUTO_INCREMENT PRIMARY KEY, todo_list_id INT NOT NULL, title VARCHAR(255) NOT NULL, is_completed TINYINT(1) DEFAULT 0, order_index INT DEFAULT 0, FOREIGN KEY (todo_list_id) REFERENCES todo_lists(id) ON DELETE CASCADE) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci");
|
||||
$conn->query("ALTER TABLE packing_lists ADD COLUMN todo_list_id INT DEFAULT NULL");
|
||||
$conn->query("ALTER TABLE packing_lists ADD CONSTRAINT fk_packing_list_todo FOREIGN KEY (todo_list_id) REFERENCES todo_lists(id) ON DELETE SET NULL");
|
||||
|
||||
$check_todo_list_id = $conn->query("SHOW COLUMNS FROM packing_lists LIKE 'todo_list_id'");
|
||||
if ($check_todo_list_id && $check_todo_list_id->num_rows == 0) {
|
||||
$conn->query("ALTER TABLE packing_lists ADD COLUMN todo_list_id INT DEFAULT NULL");
|
||||
$conn->query("ALTER TABLE packing_lists ADD CONSTRAINT fk_packing_list_todo FOREIGN KEY (todo_list_id) REFERENCES todo_lists(id) ON DELETE SET NULL");
|
||||
}
|
||||
|
||||
require_once 'header.php';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user