make v1->v3 upgrade work with --features=bundled

--features=bundled enables -DSQLITE_DEFAULT_FOREIGN_KEYS=1, and so some
operations have to be done in the proper order.

* enable foreign key enforcement all the time, so I test this more reliably.
* reorder some parts of the v1->v3 order. foreign key enforcement is
  immediate (rather than deferred) by default. and ensure
  old_recording_playback isn't left with a dangling reference to old_recording
  at the v2 stage. Instead, wait until v3 to delete tables it depends on.
This commit is contained in:
Scott Lamb
2018-03-22 08:45:32 -07:00
parent c46c50af8f
commit c0da1ef880
3 changed files with 14 additions and 8 deletions

View File

@@ -244,7 +244,12 @@ pub fn run(args: &super::Args, tx: &rusqlite::Transaction) -> Result<(), Error>
old_camera cross join sample_file_dir
where
old_camera.sub_rtsp_path != '';
"#)?;
// Add the new video_sample_entry rows, before inserting the recordings referencing them.
fix_video_sample_entry(tx)?;
tx.execute_batch(r#"
insert into recording
select
r.composite_id,
@@ -270,14 +275,6 @@ pub fn run(args: &super::Args, tx: &rusqlite::Transaction) -> Result<(), Error>
old_recording r join recording_playback p on (r.composite_id = p.composite_id);
"#)?;
fix_video_sample_entry(tx)?;
tx.execute_batch(r#"
drop table old_camera;
drop table old_recording;
drop table old_video_sample_entry;
"#)?;
Ok(())
}