Skip to content

Commit

Permalink
Add additional handling to schema upgrade
Browse files Browse the repository at this point in the history
When upgrading the backup database's schema from 3 to 4, one step is to
update any markers we've already added to the Plex database to use epoch
timestamps instead of time strings. However, if another version of
IntroEditor already ran that migration, our update query will fail. Add
some logic that checks whether the migration already ran, and if we
still can't get a valid value, reset it.
  • Loading branch information
danrahn committed Feb 21, 2023
1 parent 3975ee2 commit d1cfd3f
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions Server/MarkerBackupManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -443,8 +443,23 @@ class MarkerBackupManager {
const modifiedMarkers = await db.all(modifiedMarkersQuery);
const txn = new TransactionBuilder(db);
for (const marker of modifiedMarkers) {
const userCreated = marker.thumb_url.endsWith('*');
const date = (new Date(userCreated ? marker.thumb_url.substring(0, marker.thumb_url.length - 1) : marker.thumb_url).getTime() / 1000) * (userCreated ? -1 : 1);
let userCreated = marker.thumb_url.endsWith('*');
let date = (new Date(userCreated ? marker.thumb_url.substring(0, marker.thumb_url.length - 1) : marker.thumb_url).getTime() / 1000) * (userCreated ? -1 : 1);
if (isNaN(date)) {
// Did another instance already switch to epoch?
const asEpoch = Math.abs(marker.thumb_url);
if (isNaN(asEpoch)) {
// Bad data, reset to blank
date = '';
} else {
const year = new Date(asEpoch * 1000).getFullYear();
if (year > 1990 && year < Date.now()) {
date = marker.thumb_url;
} else {
date = '';
}
}
}
txn.addStatement(`UPDATE taggings SET thumb_url=? WHERE id=?`, [date, marker.id]);
}

Expand Down

0 comments on commit d1cfd3f

Please sign in to comment.