mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-11-25 15:43:19 +00:00
Modify DELETE triggers to delete BEFORE instead of AFTER to prevent possible foreign key constraint violations
Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
parent
1b87ec067e
commit
d2828310f2
2 changed files with 34 additions and 0 deletions
|
@ -152,4 +152,11 @@ upgrade_gravityDB(){
|
||||||
pihole-FTL sqlite3 -ni "${database}" < "${scriptPath}/17_to_18.sql"
|
pihole-FTL sqlite3 -ni "${database}" < "${scriptPath}/17_to_18.sql"
|
||||||
version=18
|
version=18
|
||||||
fi
|
fi
|
||||||
|
if [[ "$version" == "18" ]]; then
|
||||||
|
# Modify DELETE triggers to delete BEFORE instead of AFTER to prevent
|
||||||
|
# foreign key constraint violations
|
||||||
|
echo -e " ${INFO} Upgrading gravity database from version 18 to 19"
|
||||||
|
pihole-FTL sqlite3 -ni "${database}" < "${scriptPath}/18_to_19.sql"
|
||||||
|
version=19
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
27
advanced/Scripts/database_migration/gravity/18_to_19.sql
Normal file
27
advanced/Scripts/database_migration/gravity/18_to_19.sql
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
.timeout 30000
|
||||||
|
|
||||||
|
PRAGMA FOREIGN_KEYS=OFF;
|
||||||
|
|
||||||
|
BEGIN TRANSACTION;
|
||||||
|
|
||||||
|
DROP TRIGGER tr_domainlist_delete;
|
||||||
|
CREATE TRIGGER tr_domainlist_delete BEFORE DELETE ON domainlist
|
||||||
|
BEGIN
|
||||||
|
DELETE FROM domainlist_by_group WHERE domainlist_id = OLD.id;
|
||||||
|
END;
|
||||||
|
|
||||||
|
DROP TRIGGER tr_adlist_delete;
|
||||||
|
CREATE TRIGGER tr_adlist_delete BEFORE DELETE ON adlist
|
||||||
|
BEGIN
|
||||||
|
DELETE FROM adlist_by_group WHERE adlist_id = OLD.id;
|
||||||
|
END;
|
||||||
|
|
||||||
|
DROP TRIGGER tr_client_delete;
|
||||||
|
CREATE TRIGGER tr_client_delete BEFORE DELETE ON client
|
||||||
|
BEGIN
|
||||||
|
DELETE FROM client_by_group WHERE client_id = OLD.id;
|
||||||
|
END;
|
||||||
|
|
||||||
|
UPDATE info SET value = 19 WHERE property = 'version';
|
||||||
|
|
||||||
|
COMMIT;
|
Loading…
Reference in a new issue