Harden conversation replies and prioritize newest candidates
This commit is contained in:
1 parent
f98c5c732d
commit
b8e4a1bb88
23 files changed
+598
-113
No files matched your search
@@ -336,6 +336,34 @@ export function runMigrations(db: Database.Database): void {
|
||||
addColumnIfNotExists(db, 'conversation_automation_claims', 'last_attempt_at', 'INTEGER');
|
||||
addColumnIfNotExists(db, 'conversation_automation_claims', 'attempt_count', 'INTEGER NOT NULL DEFAULT 0');
|
||||
},
|
||||
() => db.exec(`
|
||||
CREATE TABLE conversation_automation_claims_with_superseded (
|
||||
account_id TEXT NOT NULL,
|
||||
conversation_id TEXT NOT NULL,
|
||||
incoming_key TEXT NOT NULL,
|
||||
status TEXT NOT NULL CHECK(status IN ('pending', 'sent', 'superseded')),
|
||||
claimed_at INTEGER NOT NULL,
|
||||
sent_at INTEGER,
|
||||
superseded_at INTEGER,
|
||||
reply_text TEXT,
|
||||
incoming_at INTEGER,
|
||||
last_attempt_at INTEGER,
|
||||
attempt_count INTEGER NOT NULL DEFAULT 0,
|
||||
PRIMARY KEY (account_id, conversation_id, incoming_key),
|
||||
FOREIGN KEY (account_id) REFERENCES reddit_accounts(account_id) ON DELETE CASCADE
|
||||
);
|
||||
INSERT INTO conversation_automation_claims_with_superseded (
|
||||
account_id, conversation_id, incoming_key, status, claimed_at, sent_at,
|
||||
reply_text, incoming_at, last_attempt_at, attempt_count
|
||||
) SELECT
|
||||
account_id, conversation_id, incoming_key, status, claimed_at, sent_at,
|
||||
reply_text, incoming_at, last_attempt_at, attempt_count
|
||||
FROM conversation_automation_claims;
|
||||
DROP TABLE conversation_automation_claims;
|
||||
ALTER TABLE conversation_automation_claims_with_superseded RENAME TO conversation_automation_claims;
|
||||
CREATE INDEX idx_conversation_automation_claims_status
|
||||
ON conversation_automation_claims(account_id, status, claimed_at);
|
||||
`),
|
||||
];
|
||||
|
||||
let currentVersion = db.pragma('user_version', { simple: true }) as number;
|
||||
|
||||
Reference in new issue
Block a user