This commit is contained in:
xadyz1 2026-07-26 15:26:09 +01:00
parent 5987db1ae4
commit bf7fa80a25
3 changed files with 25 additions and 0 deletions

21
fix-schema.js Normal file
View file

@ -0,0 +1,21 @@
const fs = require('fs');
let code = fs.readFileSync('server/db/database.js', 'utf8');
// Replace db.exec(schema) with splitting by ';' and running prepare().run()
const replacement = `
const schema = fs.readFileSync(path.join(__dirname, 'schema.sql'), 'utf8');
const statements = schema.split(';');
for (let stmt of statements) {
if (stmt.trim()) {
try {
db.prepare(stmt).run();
} catch (e) {
console.error('Schema exec error:', e.message, '\\nStatement:', stmt.substring(0, 50));
}
}
}
`;
code = code.replace("const schema = fs.readFileSync(path.join(__dirname, 'schema.sql'), 'utf8');\\ndb.exec(schema);", replacement);
fs.writeFileSync('server/db/database.js', code);
console.log('Fixed database.js');

4
server/test-exec.js Normal file
View file

@ -0,0 +1,4 @@
const Database = require('libsql');
const db = new Database(':memory:');
db.exec('CREATE TABLE foo (id INT); CREATE TABLE bar (id INT);');
console.log(db.prepare("SELECT name FROM sqlite_master WHERE type='table'").all());