From 568e6e4660b4fd362d169b4a258b217f377e7015 Mon Sep 17 00:00:00 2001 From: "J. King" Date: Sun, 1 Dec 2019 22:29:48 -0500 Subject: [PATCH] Delete dangling MySQL records when updating MySQL seems to reject queries involving arsse_folders.parent and arsse_subscription.folder, though they appear to be valid. More testing is required. --- UPGRADING | 3 +-- sql/MySQL/5.sql | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/UPGRADING b/UPGRADING index e0fa200e..a78867b1 100644 --- a/UPGRADING +++ b/UPGRADING @@ -15,8 +15,7 @@ Upgrading from 0.8.1 to 0.8.2 ============================= - The database schema has changed from rev5 to rev6; if upgrading the database - manually, apply the 5.sql file. MySQL databases may need manual - intervention to ensure foreign key constraints are not violated + manually, apply the 5.sql file Upgrading from 0.7.1 to 0.8.0 diff --git a/sql/MySQL/5.sql b/sql/MySQL/5.sql index 7e8ef7e8..2fe87f34 100644 --- a/sql/MySQL/5.sql +++ b/sql/MySQL/5.sql @@ -8,6 +8,33 @@ alter table arsse_sessions default character set utf8mb4 collate utf8mb4_unicode_ci; alter table arsse_sessions convert to character set utf8mb4 collate utf8mb4_unicode_ci; +-- Ensure referential integrity +delete from arsse_folders where + owner not in (select id from arsse_users) or + (parent is not null and parent not in (select id from arsse_folders)); +delete from arsse_subscriptions where + owner not in (select id from arsse_users) or + feed not in (select id from arsse_feeds) or + (folder is not null and folder not in (select id from arsse_folders)); +delete from arsse_articles where feed not in (select id from arsse_feeds); +delete from arsse_enclosures where article not in (select id from arsse_articles); +delete from arsse_marks where + article not in (select id from arsse_articles) or + subscription not in (select id from arsse_subscriptions); +delete from arsse_editions where article not in (select id from arsse_articles); +delete from arsse_categories where article not in (select id from arsse_articles); +delete from arsse_sessions where "user" not in (select id from arsse_users); +delete from arsse_labels where owner not in (select id from arsse_users); +delete from arsse_label_members where + label not in (select id from arsse_labels) or + article not in (select id from arsse_articles) or + subscription not in (select id from arsse_subscriptions); +delete from arsse_tags where owner not in (select id from arsse_users); +delete from arsse_tag_members where + tag not in (select id from arsse_tags) or + subscription not in (select id from arsse_subscriptions); +delete from arsse_tokens where "user" not in (select id from arsse_users); + -- Make integer foreign key referrers unsigned to match serial-type keys alter table arsse_folders modify parent bigint unsigned; alter table arsse_subscriptions modify feed bigint unsigned not null;