feat: support postgres autonomy runtime
This commit is contained in:
+6
-5
@@ -5,6 +5,7 @@ const { Worker } = require('node:worker_threads');
|
||||
const db = require('../db');
|
||||
const config = require('../config');
|
||||
const Database = require('better-sqlite3');
|
||||
const { openRuntimeDb, isPostgresEnabled } = require('../db/runtime');
|
||||
|
||||
let idb = null;
|
||||
let statsSummaryCache = null;
|
||||
@@ -46,9 +47,9 @@ function getIntelligenceDb() {
|
||||
? (path.isAbsolute(config.intelligence_db) ? config.intelligence_db : path.resolve(configDir, config.intelligence_db))
|
||||
: path.resolve(configDir, 'intelligence.sqlite'));
|
||||
|
||||
if (!fs.existsSync(rawPath)) return null;
|
||||
if (!isPostgresEnabled() && !fs.existsSync(rawPath)) return null;
|
||||
|
||||
idb = new Database(rawPath);
|
||||
idb = isPostgresEnabled() ? openRuntimeDb(rawPath, { schema: 'intelligence' }) : new Database(rawPath);
|
||||
return idb;
|
||||
}
|
||||
|
||||
@@ -153,9 +154,9 @@ async function adminRoutes(fastify) {
|
||||
if (!checkAuth(request, reply)) return;
|
||||
const intelligenceDb = getIntelligenceDb();
|
||||
if (!intelligenceDb) return { enabled: false, reason: 'intelligence database unavailable' };
|
||||
const hasSchema = intelligenceDb.prepare(
|
||||
"SELECT 1 FROM sqlite_master WHERE type='table' AND name='autonomy_jobs'"
|
||||
).get();
|
||||
const hasSchema = isPostgresEnabled()
|
||||
? intelligenceDb.prepare("SELECT 1 FROM information_schema.tables WHERE table_schema = ? AND table_name = ?").get('intelligence', 'autonomy_jobs')
|
||||
: intelligenceDb.prepare("SELECT 1 FROM sqlite_master WHERE type='table' AND name='autonomy_jobs'").get();
|
||||
if (!hasSchema) return { enabled: false, reason: 'autonomy schema is not initialized' };
|
||||
|
||||
const jobs = intelligenceDb.prepare(`
|
||||
|
||||
@@ -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