From 88e2714ec8017404240edfe0061cac945625f64e Mon Sep 17 00:00:00 2001 From: Frederic Cabassut Date: Mon, 9 Mar 2026 00:32:39 +0100 Subject: [PATCH] fix: add missing thumbnail_path migration and upload error feedback DBs created before the image upload feature had no thumbnail_path column in the attachments table. Since CREATE TABLE IF NOT EXISTS is a no-op for existing tables, the column was never added, causing silent insert failures. Add idempotent ALTER TABLE migration for thumbnail_path and surface upload errors via toast notifications instead of swallowing them silently. Co-Authored-By: Claude Opus 4.6 --- src/lib/components/ImageUpload.svelte | 5 +++++ src/lib/server/db/index.ts | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/lib/components/ImageUpload.svelte b/src/lib/components/ImageUpload.svelte index f1de17e..90e791e 100644 --- a/src/lib/components/ImageUpload.svelte +++ b/src/lib/components/ImageUpload.svelte @@ -7,6 +7,7 @@ import { optimizeImage } from '$lib/utils/image-optimize.js'; import { browser } from '$app/environment'; import { addPendingAttachment, type PendingAttachment } from '$lib/sync/idb.js'; + import { showToast } from '$lib/stores/toast.js'; interface Props { noteId: string; @@ -85,9 +86,13 @@ if (res.ok) { const attachment = await res.json(); onUpload(attachment); + } else { + console.error('Upload failed:', res.status, await res.text()); + showToast('Failed to upload image', 'error'); } } catch (err) { console.error('Upload failed:', err); + showToast('Failed to upload image', 'error'); } uploading = false; } diff --git a/src/lib/server/db/index.ts b/src/lib/server/db/index.ts index 9b6c4fd..1ec3ff5 100644 --- a/src/lib/server/db/index.ts +++ b/src/lib/server/db/index.ts @@ -85,7 +85,12 @@ sqlite.exec(` CREATE INDEX IF NOT EXISTS sync_log_timestamp_idx ON sync_log(timestamp); `); -// Idempotent migration: add featured column to attachments +// Idempotent migrations: add columns that may be missing from older DBs +try { + sqlite.exec(`ALTER TABLE attachments ADD COLUMN thumbnail_path TEXT;`); +} catch { + // Column already exists +} try { sqlite.exec(`ALTER TABLE attachments ADD COLUMN featured INTEGER NOT NULL DEFAULT 0;`); } catch {