Skip to content

Commit 3ca06bd

Browse files
committed
Add dialog text to handle out-of-sync SQLite database files #288
Signed-off-by: Steven Esser <[email protected]>
1 parent 09af571 commit 3ca06bd

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

assets/app/js/renderer.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,14 +182,39 @@ $(document).ready(() => {
182182
redrawCurrentView();
183183
}
184184

185+
function schemaChange(dbVersion, aboutCodeVersion) {
186+
dbVersion = dbVersion.split('.');
187+
aboutCodeVersion = aboutCodeVersion.split('.');
188+
189+
if (dbVersion[1] != aboutCodeVersion[1]) {
190+
return true;
191+
} else {
192+
return false;
193+
}
194+
}
195+
185196
/** Creates the database and all View objects from a SQLite file */
186197
function loadDatabase(fileName) {
187198
// Create a new database when importing a json file
188199
aboutCodeDB = new AboutCodeDB({
189200
dbName: 'aboutcode_db',
190201
dbStorage: fileName
191202
});
192-
203+
204+
// Check that that the database schema matches current schema.
205+
aboutCodeDB.sync
206+
.then((db) => db.Header.findById(1)
207+
.then((header) => {
208+
const dbVersion = header.aboutcode_manager_version;
209+
if (schemaChange(dbVersion, aboutCodeVersion)) {
210+
dialog.showErrorBox(
211+
'Old SQLite schema found at file: ' + fileName,
212+
'The SQLite schema has been updated since the last time you loaded this ' +
213+
'file.\n\n' +
214+
'Some features may not work correctly until you re-import the original' +
215+
'ScanCode JSON file to create an updated SQLite database.');
216+
}
217+
}));
193218
// Check that the database has the correct header information.
194219
aboutCodeDB.sync
195220
.then((db) => db.Header.findAll())

0 commit comments

Comments
 (0)