Add account browsing simulation

This commit is contained in:
jjbrunton committed 2026-08-11 21:40:31 +01:00
1 parent e2d7dc4b82
commit 27012399ec
31 files changed
+1476 -28

No files matched your search

+44
View File
@@ -564,6 +564,50 @@ export function runMigrations(db: Database.Database): void {
// Null keeps the adaptive allowance; a value is an operator override.
addColumnIfNotExists(db, 'account_growth_settings', 'daily_limit', 'INTEGER');
},
() => db.exec(`
CREATE TABLE IF NOT EXISTS account_browsing_settings (
account_id TEXT PRIMARY KEY,
enabled INTEGER NOT NULL DEFAULT 0 CHECK(enabled IN (0, 1)),
daily_target_min INTEGER NOT NULL DEFAULT 3,
daily_target_max INTEGER NOT NULL DEFAULT 6,
post_weight INTEGER NOT NULL DEFAULT 60,
comment_weight INTEGER NOT NULL DEFAULT 40,
quiet_hours_json TEXT NOT NULL DEFAULT '{"enabled":true,"startHour":0,"endHour":7}',
minimum_gap_ms INTEGER NOT NULL DEFAULT 2700000,
jitter_ms INTEGER NOT NULL DEFAULT 900000,
allow_nsfw INTEGER NOT NULL DEFAULT 0 CHECK(allow_nsfw IN (0, 1)),
next_due_at INTEGER,
updated_at INTEGER NOT NULL,
FOREIGN KEY (account_id) REFERENCES reddit_accounts(account_id) ON DELETE CASCADE,
CHECK(daily_target_min BETWEEN 1 AND 12),
CHECK(daily_target_max BETWEEN daily_target_min AND 12),
CHECK(post_weight >= 0 AND comment_weight >= 0 AND post_weight + comment_weight > 0)
);
CREATE TABLE IF NOT EXISTS account_browsing_decisions (
account_id TEXT NOT NULL,
thing_fullname TEXT NOT NULL,
thing_kind TEXT NOT NULL CHECK(thing_kind IN ('post', 'comment')),
post_id TEXT NOT NULL,
subreddit TEXT NOT NULL COLLATE NOCASE,
author TEXT NOT NULL,
permalink TEXT NOT NULL,
decision TEXT NOT NULL CHECK(decision IN ('simulated-upvote', 'skipped', 'rejected')),
reason TEXT NOT NULL,
discovered_at INTEGER NOT NULL,
decided_at INTEGER NOT NULL,
scheduled_session_id TEXT NOT NULL,
PRIMARY KEY (account_id, thing_fullname),
FOREIGN KEY (account_id) REFERENCES reddit_accounts(account_id) ON DELETE CASCADE
);
CREATE INDEX IF NOT EXISTS idx_account_browsing_decisions_recent
ON account_browsing_decisions(account_id, decided_at DESC);
CREATE UNIQUE INDEX IF NOT EXISTS idx_account_browsing_decisions_selected
ON account_browsing_decisions(thing_fullname)
WHERE decision = 'simulated-upvote';
CREATE INDEX IF NOT EXISTS idx_account_browsing_decisions_day
ON account_browsing_decisions(account_id, decision, decided_at);
`),
];
let currentVersion = db.pragma('user_version', { simple: true }) as number;