update
This commit is contained in:
35
test/schema-version.test.js
Normal file
35
test/schema-version.test.js
Normal file
@@ -0,0 +1,35 @@
|
||||
'use strict';
|
||||
const assert = require('node:assert');
|
||||
const fs = require('node:fs');
|
||||
const os = require('node:os');
|
||||
const path = require('node:path');
|
||||
const Database = require('better-sqlite3');
|
||||
|
||||
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'clip-mig-'));
|
||||
const db = new Database(path.join(tmp, 'h.db'));
|
||||
// Simulate an old DB without FTS5.
|
||||
db.exec(`CREATE TABLE clips (id INTEGER PRIMARY KEY AUTOINCREMENT, type TEXT, text TEXT)`);
|
||||
const { migrate } = require('../lib/migrate.js');
|
||||
|
||||
let passed = 0;
|
||||
function check(name, fn) {
|
||||
try { fn(); console.log(' ok -', name); passed++; }
|
||||
catch (e) { console.error(' FAIL -', name, e.message); process.exitCode = 1; }
|
||||
}
|
||||
|
||||
check('migrate from v1 runs without throwing', () => {
|
||||
migrate(db, 1, 2);
|
||||
});
|
||||
|
||||
let skipped = false;
|
||||
try { db.prepare('SELECT 1 FROM clips_fts LIMIT 0').all(); }
|
||||
catch (_) { skipped = true; }
|
||||
|
||||
check(skipped ? 'clips_fts not present (FTS5 unavailable)' : 'clips_fts present', () => {
|
||||
if (!skipped) {
|
||||
const rows = db.prepare('SELECT 1 FROM clips_fts LIMIT 0').all();
|
||||
assert.deepStrictEqual(rows, []);
|
||||
}
|
||||
});
|
||||
|
||||
db.close();
|
||||
Reference in New Issue
Block a user