Enhance SQLite database initialization in sqliteDb.js
Publish Docker image / build-and-push (push) Successful in 1m27s
Publish Docker image / build-and-push (push) Successful in 1m27s
- Added checks to ensure the SQLite database file exists before opening, improving resilience during container startup. - Implemented error handling for file accessibility, providing clearer error messages if the database file is not readable or writable. Made-with: Cursor
This commit is contained in:
@@ -20,6 +20,21 @@ function getDbPath() {
|
||||
if (!fs.existsSync(dir)) {
|
||||
fs.mkdirSync(dir, { recursive: true });
|
||||
}
|
||||
|
||||
// Ensure the file exists before better-sqlite3 opens it.
|
||||
// This makes container startup resilient when SQLITE_PATH points to
|
||||
// a persistent volume and database file is not created yet.
|
||||
if (!fs.existsSync(p)) {
|
||||
fs.closeSync(fs.openSync(p, 'a'));
|
||||
}
|
||||
|
||||
try {
|
||||
fs.accessSync(p, fs.constants.R_OK | fs.constants.W_OK);
|
||||
} catch (err) {
|
||||
const details = err && err.message ? err.message : String(err);
|
||||
throw new Error(`SQLite file is not readable/writable at "${p}": ${details}`);
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user