This commit is contained in:
2026-09-12 13:59:12 +08:00
commit 941ce4baab
71 changed files with 13037 additions and 0 deletions

View 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();