Changeset 5f483e3 in Klonkt for src/config/database.js
- Timestamp:
- 06/27/2026 03:01:13 PM (2 months ago)
- Branches:
- main
- Children:
- 3746f6a
- Parents:
- 98fe58a
- File:
-
- 1 edited
-
src/config/database.js (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/config/database.js
r98fe58a r5f483e3 163 163 `); 164 164 165 // ── Circles (federation) ────────────────────────────────────166 // Decentralised, asymmetric connections between solo instances.167 db.exec(`168 CREATE TABLE IF NOT EXISTS circle_links (169 id TEXT PRIMARY KEY,170 local_site_id TEXT NOT NULL,171 remote_url TEXT NOT NULL,172 remote_actor_id TEXT,173 label TEXT,174 status TEXT DEFAULT 'active',175 added_at DATETIME DEFAULT CURRENT_TIMESTAMP,176 last_synced DATETIME,177 last_error TEXT,178 UNIQUE(local_site_id, remote_url),179 FOREIGN KEY (local_site_id) REFERENCES sites(id)180 );181 CREATE TABLE IF NOT EXISTS remote_actors (182 id TEXT PRIMARY KEY,183 url TEXT UNIQUE NOT NULL,184 name TEXT,185 summary TEXT,186 avatar TEXT,187 public_key TEXT NOT NULL,188 fetched_at DATETIME DEFAULT CURRENT_TIMESTAMP189 );190 CREATE TABLE IF NOT EXISTS remote_posts (191 id TEXT PRIMARY KEY,192 actor_id TEXT NOT NULL,193 published DATETIME,194 title TEXT,195 summary TEXT,196 url TEXT,197 media_json TEXT,198 raw_json TEXT,199 fetched_at DATETIME DEFAULT CURRENT_TIMESTAMP,200 FOREIGN KEY (actor_id) REFERENCES remote_actors(id)201 );202 `);203 204 // Tags from the original post — shown in the circle feed (comma-separated string).205 ensureColumn('remote_posts', 'tags', 'TEXT');206 207 165 // Newsletter / mailing list (premium). Subscribers per site; double opt-in when SMTP 208 166 // is configured (status 'pending' until confirmed), otherwise single opt-in ('confirmed'). … … 252 210 `); 253 211 254 // Notifications: someone replies to your comment / post, or likes your post. Snapshots255 // of name/title so the list can be shown cheaply without joins.256 // NB: deliberately named 'user_notifications' — some older DBs still have a stale,257 // unused 'notifications' table with a different schema (no read column).258 db.exec(`259 CREATE TABLE IF NOT EXISTS user_notifications (260 id TEXT PRIMARY KEY,261 user_id TEXT NOT NULL,262 type TEXT NOT NULL,263 actor_id TEXT,264 actor_name TEXT,265 post_slug TEXT,266 post_title TEXT,267 url TEXT,268 read INTEGER DEFAULT 0,269 created_at DATETIME DEFAULT CURRENT_TIMESTAMP270 );271 `);272 // Older DBs may have a user_notifications table predating these columns — add273 // them before the index (which references `read`), else boot crashes.274 ensureColumn('user_notifications', 'type', 'TEXT');275 ensureColumn('user_notifications', 'actor_id', 'TEXT');276 ensureColumn('user_notifications', 'actor_name', 'TEXT');277 ensureColumn('user_notifications', 'post_slug', 'TEXT');278 ensureColumn('user_notifications', 'post_title', 'TEXT');279 ensureColumn('user_notifications', 'url', 'TEXT');280 ensureColumn('user_notifications', 'read', 'INTEGER DEFAULT 0');281 db.exec('CREATE INDEX IF NOT EXISTS idx_unotif_user ON user_notifications(user_id, read, created_at);');282 283 212 // Link-in-bio click statistics (premium #6). One counter per (site, url); the 284 213 // link-in-bio page links via /links/go/:i which counts the click and redirects. … … 293 222 `); 294 223 295 // Likes / favourites: a logged-in user can like a post. The set of296 // posts a user liked = their favourites (/favorieten page). One row297 // per (post, user); unique so that liking is idempotent.298 db.exec(`299 CREATE TABLE IF NOT EXISTS post_likes (300 post_id TEXT NOT NULL,301 user_id TEXT NOT NULL,302 created_at DATETIME DEFAULT CURRENT_TIMESTAMP,303 PRIMARY KEY (post_id, user_id)304 );305 CREATE INDEX IF NOT EXISTS idx_post_likes_user ON post_likes(user_id, created_at);306 CREATE INDEX IF NOT EXISTS idx_post_likes_post ON post_likes(post_id);307 `);308 224 309 225 // ── ActivityPub (fediverse bridge) ──────────────────────────
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)