diff --git a/server/db/upgrade/mod.rs b/server/db/upgrade/mod.rs index c6b91c8..acf2ab4 100644 --- a/server/db/upgrade/mod.rs +++ b/server/db/upgrade/mod.rs @@ -296,8 +296,25 @@ mod tests { // anything left over. assert!(!garbage.exists()); std::fs::File::create(&garbage)?; - } - if *ver == 6 { + } else if *ver == 4 { + // First version that supports signals. Add them and ensure they don't break + // subsequent upgrades. + upgraded.execute_batch( + r#" + insert into signal (id, source_uuid, type_uuid, short_name) + values (1, x'1B3889C0A59F400DA24C94EBEB19CC3A', + x'EE66270FD9C648198B339720D4CBCA6B', 'a'), + (2, x'A4A73D9A53424EBCB9F6366F1E5617FA', + x'EE66270FD9C648198B339720D4CBCA6B', 'b'); + insert into signal_type_enum (type_uuid, value, name, motion, color) + values (x'EE66270FD9C648198B339720D4CBCA6B', 1, 'still', 0, 'black'), + (x'EE66270FD9C648198B339720D4CBCA6B', 2, 'moving', 1, 'red'); + insert into signal_camera (signal_id, camera_id, type) + values (1, 1, 0), + (2, 1, 1); + "#, + )?; + } else if *ver == 6 { // Check that the pasp was set properly. let mut stmt = upgraded.prepare( r#" diff --git a/server/db/upgrade/v3_to_v4.rs b/server/db/upgrade/v3_to_v4.rs index 0c25547..3b0493e 100644 --- a/server/db/upgrade/v3_to_v4.rs +++ b/server/db/upgrade/v3_to_v4.rs @@ -27,13 +27,6 @@ pub fn run(_args: &super::Args, tx: &rusqlite::Transaction) -> Result<(), Error> color text ); - create table signal_camera ( - signal_id integer references signal (id), - camera_id integer references camera (id), - type integer not null, - primary key (signal_id, camera_id) - ) without rowid; - create table signal_change ( time_90k integer primary key, changes blob not null @@ -69,6 +62,13 @@ pub fn run(_args: &super::Args, tx: &rusqlite::Transaction) -> Result<(), Error> from old_camera; + create table signal_camera ( + signal_id integer references signal (id), + camera_id integer references camera (id), + type integer not null, + primary key (signal_id, camera_id) + ) without rowid; + alter table stream rename to old_stream; create table stream ( id integer primary key, diff --git a/server/db/upgrade/v6_to_v7.rs b/server/db/upgrade/v6_to_v7.rs index b15074b..e2d13f1 100644 --- a/server/db/upgrade/v6_to_v7.rs +++ b/server/db/upgrade/v6_to_v7.rs @@ -457,10 +457,9 @@ pub fn run(_args: &super::Args, tx: &rusqlite::Transaction) -> Result<(), Error> composite_id integer not null, primary key (sample_file_dir_id, composite_id) ) without rowid; - drop index recording_cover; insert into garbage select * from old_garbage; drop table old_garbage; - + drop index recording_cover; alter table recording rename to old_recording; create table recording ( composite_id integer primary key, @@ -510,8 +509,8 @@ pub fn run(_args: &super::Args, tx: &rusqlite::Transaction) -> Result<(), Error> video_index blob not null check (length(video_index) > 0) ); insert into recording_playback select * from old_recording_playback; - drop table old_signal; drop table signal_camera; + drop table old_signal; drop table old_recording_playback; drop table old_recording_integrity; drop table old_recording;