add event_date column to event_knowledge and event_predictions tables; update related logic in admin panel and augorWorker

This commit is contained in:
ImBenji
2026-04-23 16:21:30 +01:00
parent c31f8b0b16
commit 8aa10d9bc2
4 changed files with 365 additions and 89 deletions
+19 -21
View File
@@ -358,7 +358,7 @@ async function adminRoutes(fastify) {
});
// raw sql console
// raw sql console — supports multiple statements separated by ;
fastify.post('/admin/api/sql', async (request, reply) => {
if (!checkAuth(request, reply)) return;
@@ -368,29 +368,27 @@ async function adminRoutes(fastify) {
const target = database === 'intelligence' ? getIntelligenceDb() : db;
if (!target) { reply.code(400); return { error: 'database not available' }; }
try {
const stmt = target.prepare(sql);
const start = Date.now();
// split on semicolons, drop empty statements
const statements = sql.split(';').map(s => s.trim()).filter(s => s.length > 0);
let rows, changes, lastInsertRowid;
if (stmt.reader) {
rows = stmt.all();
} else {
const info = stmt.run();
changes = info.changes;
lastInsertRowid = info.lastInsertRowid;
const results = [];
const start = Date.now();
for (const s of statements) {
try {
const stmt = target.prepare(s);
if (stmt.reader) {
results.push({ sql: s, rows: stmt.all() });
} else {
const info = stmt.run();
results.push({ sql: s, changes: info.changes, lastInsertRowid: info.lastInsertRowid });
}
} catch (err) {
results.push({ sql: s, error: err.message });
}
return {
rows: rows || null,
changes: changes ?? null,
lastInsertRowid: lastInsertRowid ?? null,
elapsed: Date.now() - start,
};
} catch (err) {
reply.code(400);
return { error: err.message };
}
return { results, elapsed: Date.now() - start };
});
// stats for dashboard header