Fix: Auto-Migration in backpacks.php, um SQL-Fehler bei fehlenden Spalten zu verhindern.
All checks were successful
Docker Build & Push / build-and-push (push) Successful in 20s
All checks were successful
Docker Build & Push / build-and-push (push) Successful in 20s
This commit is contained in:
@@ -32,6 +32,17 @@ if (isset($_POST['delete_backpack_id'])) {
|
||||
}
|
||||
}
|
||||
|
||||
// AUTO-MIGRATION: Check columns to prevent SQL errors
|
||||
$check_col = $conn->query("SHOW COLUMNS FROM backpacks LIKE 'product_url'");
|
||||
if ($check_col && $check_col->num_rows == 0) {
|
||||
$conn->query("ALTER TABLE backpacks ADD COLUMN product_url VARCHAR(255) DEFAULT NULL AFTER image_url");
|
||||
}
|
||||
$check_col_c = $conn->query("SHOW COLUMNS FROM backpack_compartments LIKE 'linked_article_id'");
|
||||
if ($check_col_c && $check_col_c->num_rows == 0) {
|
||||
$conn->query("ALTER TABLE backpack_compartments ADD COLUMN linked_article_id INT DEFAULT NULL");
|
||||
$conn->query("ALTER TABLE backpack_compartments ADD CONSTRAINT fk_bc_article FOREIGN KEY (linked_article_id) REFERENCES articles(id) ON DELETE SET NULL");
|
||||
}
|
||||
|
||||
// Fetch Backpacks (Personal + Household)
|
||||
$household_id = null;
|
||||
$stmt_hh = $conn->prepare("SELECT household_id FROM users WHERE id = ?");
|
||||
@@ -43,10 +54,6 @@ if ($row = $res_hh->fetch_assoc()) {
|
||||
}
|
||||
|
||||
$backpacks = [];
|
||||
// AUTO-MIGRATION: Check if product_url column exists (just to be safe for display)
|
||||
// Ideally handled in edit_backpack but good to be safe.
|
||||
$check_col = $conn->query("SHOW COLUMNS FROM backpacks LIKE 'product_url'");
|
||||
$has_product_url = ($check_col && $check_col->num_rows > 0);
|
||||
|
||||
$sql = "SELECT b.*, u.username as owner_name,
|
||||
(SELECT SUM(a.weight_grams)
|
||||
|
||||
Reference in New Issue
Block a user