Retire removed accounts instead of deleting them

Removing an account had no path at all, so a dead session could only be
left running or hand-edited out of the database. The first cut deleted the
account and everything it owned, which threw away conversations and media
that are worth keeping.

Retire instead: keep the row and every row it produced, destroy the stored
cookies and Matrix token. Wiping the credentials is what makes sending and
syncing impossible rather than merely disabled — isEnabledAccount requires
a verified status, so no runtime ever starts, and no session survives for
anything to use. setActive, markLoginRequired and the background credential
refresh now skip retired accounts so none of them quietly revives one;
re-importing a session deliberately does.

Keeping the content visible needed more than keeping the rows. Conversations
and media are only served from running runtimes, so a retired account's
history would have disappeared from the dashboard regardless. Media already
reads the account content table for every listed account. Conversations now
have an archive path that reads the stored ActiveChat payloads directly.

Every write path refuses a retired conversation with a 409: send-reply,
both suggest endpoints, share-media, shareable-media and all read-state
writes. Lazy-loading detail is skipped too — the fallback chat service
belongs to a different account, so it would sync the wrong session and
write the wrong cache. Archived detail derives conversation state from the
transcript alone for the same reason.

Migration 32 rebuilds reddit_accounts to admit the new status, with foreign
keys off and a foreign_key_check before they are restored, as migration 11
does. Two migration tests rewound user_version by counting back from the
head, which silently breaks whenever a migration is appended; they now
target absolute versions.

Conversations never opened before removal keep only their summary. Message
history is lazy-loaded on first open and there is no session left to fetch
the rest with.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Jamie BruntonandClaude Opus 5 committed 2026-08-12 08:58:22 +01:00
1 parent 3f60f7f665
commit a9cea7ed18
16 files changed
+433 -97

No files matched your search

+8 -4
View File
@@ -13,6 +13,8 @@ const OTHER_ACCOUNT = '@t2_other:reddit.com';
// Browsing migrations depend on the growth tables, so a pre-growth fixture
// must rewind past both the growth sequence and the later browsing additions.
const GROWTH_MIGRATION_COUNT = 7;
/** Schema version that first creates the growth tables. */
const FIRST_GROWTH_MIGRATION = 24;
function thread(id: string, overrides: Partial<RedditPost> = {}): RedditPost {
return {
@@ -507,14 +509,16 @@ describe('AccountGrowthRepository', () => {
});
describe('growth migration', () => {
/** Rewinds past every growth migration so they replay from a pre-growth state. */
/**
* Rewinds past every growth migration so they replay from a pre-growth state.
* The target is absolute: growth's first migration is 24, and counting back
* from the head silently breaks every time a migration is appended.
*/
function rewindPastGrowth(db: Database.Database): void {
const version = db.pragma('user_version', { simple: true }) as number;
db.exec('DROP TABLE account_growth_comments');
db.exec('DROP TABLE account_growth_subreddits');
db.exec('DROP TABLE account_growth_settings');
// Also rewind the later conversation-learning migration.
db.pragma(`user_version = ${version - GROWTH_MIGRATION_COUNT - 1}`);
db.pragma(`user_version = ${FIRST_GROWTH_MIGRATION - 1}`);
}
it('upgrades a database created before growth existed', () => {