diff --git a/fix-schema.js b/fix-schema.js new file mode 100644 index 0000000..9cf6d39 --- /dev/null +++ b/fix-schema.js @@ -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'); diff --git a/server/db/remote_display.db-client_wal_index b/server/db/remote_display.db-client_wal_index index 26dc66d..b23f92d 100644 Binary files a/server/db/remote_display.db-client_wal_index and b/server/db/remote_display.db-client_wal_index differ diff --git a/server/test-exec.js b/server/test-exec.js new file mode 100644 index 0000000..8b3e31e --- /dev/null +++ b/server/test-exec.js @@ -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());