fix: prevent duplicate outreach and follow-ups
This commit is contained in:
1 parent
acc610c2bf
commit
5c01d7d9aa
9 files changed
+274
-14
No files matched your search
+33
-1
@@ -107,7 +107,7 @@ describe('Database Client', () => {
|
||||
.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%'")
|
||||
.all() as { name: string }[];
|
||||
// Existing domain/config tables plus account, conversation, sync and media ownership stores.
|
||||
expect(tables.length).toBe(14);
|
||||
expect(tables.length).toBe(15);
|
||||
});
|
||||
|
||||
it('tracks schema version and migrates a legacy sent_messages table transactionally', () => {
|
||||
@@ -133,6 +133,38 @@ describe('Database Client', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('backfills global recipient suppression from sent messages and known conversations', () => {
|
||||
runMigrations(db);
|
||||
db.prepare(`
|
||||
INSERT INTO reddit_conversations (
|
||||
account_id, conversation_id, username, room_name, payload_json, updated_at
|
||||
) VALUES (?, 'old-room', 'Old_Contact', 'Old Contact', '{}', 20)
|
||||
`).run('__legacy_unassigned__');
|
||||
db.prepare(`
|
||||
INSERT INTO processed_posts (account_id, id, subreddit, author, title, processed_at)
|
||||
VALUES (?, 'old-post', 'test', 'sent-contact', 'title', 10)
|
||||
`).run('__legacy_unassigned__');
|
||||
db.prepare(`
|
||||
INSERT INTO sent_messages (
|
||||
account_id, post_id, recipient, subject, message, sent_at
|
||||
) VALUES (?, 'old-post', 'Sent_Contact', 'subject', 'message', 11)
|
||||
`).run('__legacy_unassigned__');
|
||||
|
||||
const latestVersion = db.pragma('user_version', { simple: true }) as number;
|
||||
db.exec(`
|
||||
DELETE FROM recipient_suppressions;
|
||||
DROP TABLE conversation_automation_claims;
|
||||
`);
|
||||
db.pragma(`user_version = ${latestVersion - 1}`);
|
||||
runMigrations(db);
|
||||
|
||||
expect(db.prepare('SELECT recipient, reason FROM recipient_suppressions ORDER BY recipient COLLATE NOCASE').all())
|
||||
.toEqual([
|
||||
{ recipient: 'Old_Contact', reason: 'historical-conversation' },
|
||||
{ recipient: 'Sent_Contact', reason: 'sent-message-history' },
|
||||
]);
|
||||
});
|
||||
|
||||
it('processed_posts has correct schema', () => {
|
||||
runMigrations(db);
|
||||
const columns = db.prepare('PRAGMA table_info(processed_posts)').all() as { name: string; notnull: number }[];
|
||||
|
||||
Reference in new issue
Block a user