feat: support postgres autonomy runtime
This commit is contained in:
@@ -1,14 +1,16 @@
|
||||
const path = require('path');
|
||||
const Database = require('better-sqlite3');
|
||||
const { openRuntimeDb, isPostgresEnabled } = require('../db/runtime');
|
||||
|
||||
const intelligencePath = process.env.INTELLIGENCE_DB || path.resolve(process.cwd(), 'intelligence.sqlite');
|
||||
const db = new Database(intelligencePath, { readonly: true });
|
||||
const db = openRuntimeDb(intelligencePath, { schema: 'intelligence', readonly: true });
|
||||
|
||||
async function autonomyRoutes(fastify) {
|
||||
fastify.get('/health', async () => ({ ok: true, service: 'duriin-api' }));
|
||||
|
||||
fastify.get('/autonomy/status', async () => {
|
||||
const exists = db.prepare("SELECT 1 FROM sqlite_master WHERE type='table' AND name='autonomy_jobs'").get();
|
||||
const exists = isPostgresEnabled()
|
||||
? db.prepare("SELECT 1 FROM information_schema.tables WHERE table_schema = ? AND table_name = ?").get('intelligence', 'autonomy_jobs')
|
||||
: db.prepare("SELECT 1 FROM sqlite_master WHERE type='table' AND name='autonomy_jobs'").get();
|
||||
if (!exists) return { enabled: false, reason: 'autonomy schema is not initialized' };
|
||||
const jobs = db.prepare(`
|
||||
SELECT lane, status, COUNT(*) AS count
|
||||
|
||||
Reference in New Issue
Block a user