add event_date column to event_knowledge and event_predictions tables; update related logic in admin panel and augorWorker
This commit is contained in:
+19
-21
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user