Changeset 7881080 in Klonkt for src/config/database.js


Ignore:
Timestamp:
06/18/2026 03:28:34 AM (3 months ago)
Author:
roboburr <roboburr@…>
Branches:
main
Children:
8398935
Parents:
98ecf51
Message:

Hub #3: explicit is_primary flag + shared getPrimarySite() (DRY)

The "oldest site = primary site" assumption was duplicated independently in
resolveSite, hub.js, account.js and admin.js (fragile: if the oldest happened
to be an artist site, the hub home would be wrong). Now:

  • sites.is_primary column + backfill (marks the oldest if none is primary yet; ensurePrimarySite sets it on fresh installs) → existing behaviour exactly preserved.
  • one getPrimarySite() helper (is_primary, fallback oldest) replaces the 4 copies.
  • god can CHOOSE the primary/main site: ★ button + "primary" badge on /admin/sites (exactly one primary via a transaction).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@…>

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/config/database.js

    r98ecf51 r7881080  
    5050  ensureColumn('sites', 'allow_circle', 'INTEGER DEFAULT 1');
    5151
     52  // Eén EXPLICIETE primaire/hoofd-site (= de bedrijfs-/labelsite in hub-modus,
     53  // de enige site in solo) i.p.v. de fragiele "oudste = hoofd"-conventie die op
     54  // 4 plekken gedupliceerd stond. Backfill: markeer de oudste als er nog geen
     55  // primaire site is, zodat bestaand gedrag exact behouden blijft.
     56  ensureColumn('sites', 'is_primary', 'INTEGER DEFAULT 0');
     57  try {
     58    const hasPrimary = db.prepare('SELECT 1 FROM sites WHERE is_primary = 1 LIMIT 1').get();
     59    if (!hasPrimary) {
     60      const oldest = db.prepare('SELECT id FROM sites ORDER BY created_at ASC LIMIT 1').get();
     61      if (oldest) db.prepare('UPDATE sites SET is_primary = 1 WHERE id = ?').run(oldest.id);
     62    }
     63  } catch (e) { /* sites-tabel nog leeg/afwezig bij verse init — ensurePrimarySite regelt 't */ }
     64
    5265  // v9 audit additions —————————————————————————————————————————
    5366  // SEO/social columns the v9 template uses (most live in 001-init.sql already
Note: See TracChangeset for help on using the changeset viewer.