Changeset 9a34d31 in Klonkt for src/services


Ignore:
Timestamp:
06/21/2026 06:41:31 PM (3 months ago)
Author:
roboburr <roboburr@…>
Branches:
main
Children:
e25438a
Parents:
c9c6a2d
Message:

fix(notifications): table renamed to user_notifications (collision with stale table)

Older DBs still have an unused 'notifications' table (different schema, no
read column) -> CREATE TABLE IF NOT EXISTS became a no-op and the index on
read crashed the boot (demo + demohub in crash loop). Table + queries now
use user_notifications.

Co-Authored-By: Claude <noreply@…>

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/services/NotificationService.js

    rc9c6a2d r9a34d31  
    1313  try {
    1414    db.prepare(`
    15       INSERT INTO notifications (id, user_id, type, actor_id, actor_name, post_slug, post_title, url, read)
     15      INSERT INTO user_notifications (id, user_id, type, actor_id, actor_name, post_slug, post_title, url, read)
    1616      VALUES (?, ?, ?, ?, ?, ?, ?, ?, 0)
    1717    `).run(randomUUID(), userId, type, actorId || null, actorName || null, postSlug || null, postTitle || null, url || null);
     
    2121export function unreadCount(userId) {
    2222  if (!userId) return 0;
    23   try { return db.prepare('SELECT COUNT(*) AS c FROM notifications WHERE user_id = ? AND read = 0').get(userId).c; }
     23  try { return db.prepare('SELECT COUNT(*) AS c FROM user_notifications WHERE user_id = ? AND read = 0').get(userId).c; }
    2424  catch { return 0; }
    2525}
     
    2727export function list(userId, limit = 50) {
    2828  if (!userId) return [];
    29   try { return db.prepare('SELECT * FROM notifications WHERE user_id = ? ORDER BY created_at DESC LIMIT ?').all(userId, limit); }
     29  try { return db.prepare('SELECT * FROM user_notifications WHERE user_id = ? ORDER BY created_at DESC LIMIT ?').all(userId, limit); }
    3030  catch { return []; }
    3131}
     
    3333export function markAllRead(userId) {
    3434  if (!userId) return;
    35   try { db.prepare('UPDATE notifications SET read = 1 WHERE user_id = ? AND read = 0').run(userId); } catch { /* noop */ }
     35  try { db.prepare('UPDATE user_notifications SET read = 1 WHERE user_id = ? AND read = 0').run(userId); } catch { /* noop */ }
    3636}
    3737
Note: See TracChangeset for help on using the changeset viewer.