mirror of
https://github.com/scottlamb/moonfire-nvr.git
synced 2024-12-26 15:15:56 -05:00
test and fix signal_camera upgrade problems
- after 3->4 upgrade, it left the foreign key referring to the nonexistent old_camera table. Likely no one who did the upgrade has ever inserted anything into this table, so no one's noticed. - 6->7 upgrade dropped tables in the wrong order, so if there was anything in the signal_camera table, the upgrade would fail.
This commit is contained in:
parent
363fc8a267
commit
08cef6e790
@ -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#"
|
||||
|
@ -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,
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user