Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

db: Allow DELETE FROM Devices, cascade Media and EventsCam #696

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion misc/sql/installed_db_version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3000012
3010400
11 changes: 11 additions & 0 deletions misc/sql/mysql-upgrade/3010400/delete-device-cascade.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

echo '
ALTER TABLE EventsCam DROP CONSTRAINT `EventsCam_ibfk_3`;
ALTER TABLE EventsCam ADD CONSTRAINT `EventsCam_ibfk_3` FOREIGN KEY (`device_id`) REFERENCES `Devices` (`id`) ON UPDATE CASCADE ON DELETE CASCADE;

ALTER TABLE Media DROP CONSTRAINT `Media_ibfk_1`;
ALTER TABLE Media ADD CONSTRAINT `Media_ibfk_1` FOREIGN KEY (`device_id`) REFERENCES `Devices` (`id`) ON UPDATE CASCADE ON DELETE CASCADE;
' | mysql -h"$host" -D"$dbname" -u"$user" -p"$password"

exit 0
4 changes: 2 additions & 2 deletions misc/sql/schema_mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ CREATE TABLE `EventsCam` (
KEY `time_index` (`time`) USING BTREE,
CONSTRAINT `EventsCam_ibfk_1` FOREIGN KEY (`media_id`) REFERENCES `Media` (`id`) ON DELETE CASCADE,
CONSTRAINT `EventsCam_ibfk_2` FOREIGN KEY (`level_id`) REFERENCES `EventLevels` (`id`),
CONSTRAINT `EventsCam_ibfk_3` FOREIGN KEY (`device_id`) REFERENCES `Devices` (`id`) ON UPDATE CASCADE,
CONSTRAINT `EventsCam_ibfk_3` FOREIGN KEY (`device_id`) REFERENCES `Devices` (`id`) ON UPDATE CASCADE ON DELETE CASCADE,
CONSTRAINT `EventsCam_ibfk_4` FOREIGN KEY (`type_id`) REFERENCES `EventTypesCam` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
Expand Down Expand Up @@ -227,7 +227,7 @@ CREATE TABLE `Media` (
`archive` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
KEY `device_id` (`device_id`),
CONSTRAINT `Media_ibfk_1` FOREIGN KEY (`device_id`) REFERENCES `Devices` (`id`) ON UPDATE CASCADE
CONSTRAINT `Media_ibfk_1` FOREIGN KEY (`device_id`) REFERENCES `Devices` (`id`) ON UPDATE CASCADE ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `OnvifEvents`;
Expand Down
Loading