26 lines
976 B
JavaScript
26 lines
976 B
JavaScript
#!/usr/bin/env node
|
|
|
|
const path = require('path');
|
|
const Database = require('better-sqlite3');
|
|
const { initAutonomySchema } = require('../src/autonomy/schema');
|
|
|
|
const sourcePath = process.env.LEGACY_INTELLIGENCE_DB || path.resolve(process.cwd(), 'intelligence.sqlite');
|
|
const db = new Database(sourcePath);
|
|
db.pragma('journal_mode = WAL');
|
|
initAutonomySchema(db);
|
|
const insert = db.prepare(`
|
|
INSERT OR IGNORE INTO autonomy_legacy_records(source_table, source_id, payload)
|
|
VALUES (?, ?, ?)
|
|
`);
|
|
const tx = db.transaction(() => {
|
|
for (const table of ['event_predictions', 'trade_signals', 'company_facts', 'company_relationships']) {
|
|
const exists = db.prepare("SELECT 1 FROM sqlite_master WHERE type='table' AND name=?").get(table);
|
|
if (!exists) continue;
|
|
const rows = db.prepare(`SELECT * FROM ${table}`).all();
|
|
for (const row of rows) insert.run(table, row.id, JSON.stringify(row));
|
|
console.log(`${table}: ${rows.length}`);
|
|
}
|
|
});
|
|
tx();
|
|
db.close();
|