test
This commit is contained in:
@@ -16,6 +16,14 @@ const migrations = [
|
|||||||
// used to run (wrapped in try/catch) on every boot are folded into schema.js.
|
// used to run (wrapped in try/catch) on every boot are folded into schema.js.
|
||||||
// Nothing to do here — this entry exists to mark v1 as the consolidated baseline.
|
// Nothing to do here — this entry exists to mark v1 as the consolidated baseline.
|
||||||
(_db) => {},
|
(_db) => {},
|
||||||
|
|
||||||
|
(db) => {
|
||||||
|
db.exec(`
|
||||||
|
ALTER TABLE episodes ADD COLUMN last_accessed_at INTEGER;
|
||||||
|
ALTER TABLE episodes ADD COLUMN access_count INTEGER NOT NULL DEFAULT 0;
|
||||||
|
`)
|
||||||
|
db.exec(`UPDATE episdoes SET last_accessed_at = created_at WHERE last_accessed_at IS NULL`)
|
||||||
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
const LATEST_VERSION = migrations.length;
|
const LATEST_VERSION = migrations.length;
|
||||||
|
|||||||
@@ -21,7 +21,9 @@ const schema = `
|
|||||||
ai_response TEXT NOT NULL,
|
ai_response TEXT NOT NULL,
|
||||||
created_at INTEGER NOT NULL DEFAULT (unixepoch()),
|
created_at INTEGER NOT NULL DEFAULT (unixepoch()),
|
||||||
token_count INTEGER,
|
token_count INTEGER,
|
||||||
metadata TEXT
|
metadata TEXT,
|
||||||
|
last_accessed_at INTEGER,
|
||||||
|
access_count INTEGER NOT NULL DEFAULT 0;
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS entities (
|
CREATE TABLE IF NOT EXISTS entities (
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
// scratch.js — delete after
|
||||||
|
const Database = require('better-sqlite3');
|
||||||
|
const { migrate, LATEST_VERSION } = require('./packages/memory-service/src/db/migrations');
|
||||||
|
const db = new Database('data/nexusai.test.db');
|
||||||
|
console.log('LATEST_VERSION:', LATEST_VERSION); // expect 2
|
||||||
|
console.log('before:', db.pragma('user_version', { simple: true }));
|
||||||
|
migrate(db);
|
||||||
|
console.log('after:', db.pragma('user_version', { simple: true })); // expect 2
|
||||||
|
console.log(db.prepare('SELECT last_accessed_at, access_count FROM episodes LIMIT 3').all());
|
||||||
Reference in New Issue
Block a user