feat: persist settings and enrich conversation context
This commit is contained in:
1 parent
a36723a325
commit
2c100d72b6
84 files changed
+2248
-644
No files matched your search
+51
-1
@@ -3,7 +3,7 @@ import type { Config } from '../config/index.js';
|
||||
import path from 'path';
|
||||
import fs from 'fs';
|
||||
|
||||
export function createDatabase(config: Config): Database.Database {
|
||||
export function createDatabase(config: Pick<Config, 'database'>): Database.Database {
|
||||
const dbPath = config.database.path === ':memory:'
|
||||
? ':memory:'
|
||||
: path.resolve(process.cwd(), config.database.path);
|
||||
@@ -142,6 +142,56 @@ export function runMigrations(db: Database.Database): void {
|
||||
FOREIGN KEY (sent_message_id) REFERENCES sent_messages(id)
|
||||
);
|
||||
`),
|
||||
() => {
|
||||
addColumnIfNotExists(db, 'processed_posts', 'post_url', 'TEXT');
|
||||
addColumnIfNotExists(db, 'activity_log', 'post_title', 'TEXT');
|
||||
addColumnIfNotExists(db, 'activity_log', 'post_url', 'TEXT');
|
||||
db.exec(`
|
||||
UPDATE processed_posts
|
||||
SET post_url = 'https://www.reddit.com/r/' || subreddit || '/comments/' || id || '/'
|
||||
WHERE post_url IS NULL;
|
||||
|
||||
UPDATE activity_log
|
||||
SET
|
||||
post_title = (
|
||||
SELECT pp.title
|
||||
FROM sent_messages sm
|
||||
JOIN processed_posts pp ON pp.id = sm.post_id
|
||||
WHERE sm.recipient = activity_log.recipient COLLATE NOCASE
|
||||
AND sm.sent_at <= activity_log.timestamp
|
||||
ORDER BY sm.sent_at DESC
|
||||
LIMIT 1
|
||||
),
|
||||
post_url = (
|
||||
SELECT pp.post_url
|
||||
FROM sent_messages sm
|
||||
JOIN processed_posts pp ON pp.id = sm.post_id
|
||||
WHERE sm.recipient = activity_log.recipient COLLATE NOCASE
|
||||
AND sm.sent_at <= activity_log.timestamp
|
||||
ORDER BY sm.sent_at DESC
|
||||
LIMIT 1
|
||||
),
|
||||
image_url = COALESCE(image_url, (
|
||||
SELECT pp.image_url
|
||||
FROM sent_messages sm
|
||||
JOIN processed_posts pp ON pp.id = sm.post_id
|
||||
WHERE sm.recipient = activity_log.recipient COLLATE NOCASE
|
||||
AND sm.sent_at <= activity_log.timestamp
|
||||
ORDER BY sm.sent_at DESC
|
||||
LIMIT 1
|
||||
))
|
||||
WHERE type = 'sent'
|
||||
AND recipient IS NOT NULL
|
||||
AND post_url IS NULL;
|
||||
`);
|
||||
},
|
||||
() => db.exec(`
|
||||
CREATE TABLE IF NOT EXISTS app_config (
|
||||
id INTEGER PRIMARY KEY CHECK(id = 1),
|
||||
config_json TEXT NOT NULL,
|
||||
updated_at INTEGER NOT NULL
|
||||
);
|
||||
`),
|
||||
];
|
||||
|
||||
let currentVersion = db.pragma('user_version', { simple: true }) as number;
|
||||
|
||||
Reference in new issue
Block a user