diff --git a/sql/MySQL/7.sql b/sql/MySQL/7.sql index 5d4fa9f..defdb98 100644 --- a/sql/MySQL/7.sql +++ b/sql/MySQL/7.sql @@ -111,18 +111,18 @@ insert into arsse_categories(article, name) join arsse_categories as c on m.article = c.article where m.id <> m.article; --- Drop the subscription column from the label members table as it is no longer needed (there is now a direct link between articles and subscriptions) -alter table arsse_label_members drop foreign key arsse_label_members_ibfk_3; -alter table arsse_label_members drop column subscription; - -- Create label associations for renumbered articles insert into arsse_label_members select - label, m.id, assigned, l.modified + label, m.id, subscription, assigned, l.modified from arsse_articles_map as m - join arsse_label_members as l using(article) + join arsse_label_members as l using(article, subscription) where m.id <> m.article; +-- Drop the subscription column from the label members table as it is no longer needed (there is now a direct link between articles and subscriptions) +alter table arsse_label_members drop foreign key arsse_label_members_ibfk_3; +alter table arsse_label_members drop column subscription; + -- Clean up the articles table: delete obsolete rows, add necessary constraints on new columns which could not be satisfied before inserting information, and drop the obsolete feed column delete from arsse_articles where id in (select article from arsse_articles_map where id <> article); delete from arsse_articles where subscription is null; diff --git a/sql/PostgreSQL/7.sql b/sql/PostgreSQL/7.sql index c0dbf15..0fe0e48 100644 --- a/sql/PostgreSQL/7.sql +++ b/sql/PostgreSQL/7.sql @@ -106,17 +106,17 @@ insert into arsse_categories(article, name) join arsse_categories as c on m.article = c.article where m.id <> m.article; --- Drop the subscription column from the label members table as it is no longer needed (there is now a direct link between articles and subscriptions) -alter table arsse_label_members drop column subscription; - -- Create label associations for renumbered articles insert into arsse_label_members select - label, m.id, assigned, l.modified + label, m.id, subscription, assigned, l.modified from arsse_articles_map as m - join arsse_label_members as l using(article) + join arsse_label_members as l using(article, subscription) where m.id <> m.article; +-- Drop the subscription column from the label members table as it is no longer needed (there is now a direct link between articles and subscriptions) +alter table arsse_label_members drop column subscription; + -- Clean up the articles table: delete obsolete rows, add necessary constraints on new columns which could not be satisfied before inserting information, and drop the obsolete feed column delete from arsse_articles where id in (select article from arsse_articles_map where id <> article); delete from arsse_articles where subscription is null; diff --git a/sql/SQLite3/7.sql b/sql/SQLite3/7.sql index 9394597..d26f9be 100644 --- a/sql/SQLite3/7.sql +++ b/sql/SQLite3/7.sql @@ -98,7 +98,7 @@ insert into arsse_enclosures(article, url, type) from arsse_articles_map as m join arsse_enclosures as e on m.article = e.article where m.id <> m.article; -delete from arsse_enclosures where article in (select article from arsse_articles_map where id <> article); +delete from arsse_enclosures where article in (select article from arsse_articles_map where id <> article) or article not in (select id from arsse_articles_map); -- Create categories for renumbered articles and delete obsolete categories insert into arsse_categories(article, name) @@ -107,7 +107,7 @@ insert into arsse_categories(article, name) from arsse_articles_map as m join arsse_categories as c on m.article = c.article where m.id <> m.article; -delete from arsse_categories where article in (select article from arsse_articles_map where id <> article); +delete from arsse_categories where article in (select article from arsse_articles_map where id <> article) or article not in (select id from arsse_articles_map); -- Create a new label-associations table which omits the subscription column and populate it with new data create table arsse_label_members_new( @@ -122,7 +122,7 @@ insert into arsse_label_members_new select label, m.id, assigned, l.modified from arsse_articles_map as m - join arsse_label_members as l using(article); + join arsse_label_members as l using(article, subscription); -- Create a new subscriptions table which combines the feeds table create table arsse_subscriptions_new( diff --git a/tests/cases/Db/BaseUpdate.php b/tests/cases/Db/BaseUpdate.php index 50d6a4e..2e7b4ac 100644 --- a/tests/cases/Db/BaseUpdate.php +++ b/tests/cases/Db/BaseUpdate.php @@ -210,34 +210,57 @@ QUERY_TEXT INSERT INTO arsse_icons(id, url) values (4, 'https://example.org/icon'), (12, 'https://example.net/icon'); - insert into arsse_feeds values + insert into arsse_feeds(id, url, title, source, updated, modified, next_fetch, orphaned, etag, err_count, err_msg, username, password, size, icon) values (1, 'https://example.com/rss', 'Title 1', 'https://example.com/', '2001-06-13 06:55:23', '2001-06-13 06:56:23', '2001-06-13 06:57:23', '2001-06-13 06:54:23', '"ook"', 42, 'Some error', 'johndoe', 'secret', 47, null), -- This feed has no subscriptions, so should not be seen in the new table (2, 'https://example.org/rss', 'Title 2', 'https://example.org/', '2001-06-14 06:55:23', '2001-06-14 06:56:23', '2001-06-14 06:57:23', '2001-06-14 06:54:23', '"eek"', 5, 'That error', 'janedoe', 'secret', 2112, 4), (3, 'https://example.net/rss', 'Title 3', 'https://example.net/', '2001-06-15 06:55:23', '2001-06-15 06:56:23', '2001-06-15 06:57:23', '2001-06-15 06:54:23', '"ack"', 44, 'This error', '', '', 3, 12); - insert into arsse_users values + insert into arsse_users(id,password,num,admin) values ('a', 'xyz', 1, 0), ('b', 'abc', 2, 0), ('c', 'gfy', 5, 1); insert into arsse_folders(id, owner, parent, name) values (1337, 'a', null, 'ook'), (4400, 'c', null, 'eek'); - insert into arsse_subscriptions values + insert into arsse_subscriptions(id, owner, feed, added, modified, title, order_type, pinned, folder, keep_rule, block_rule, scrape) values (1, 'a', 1, '2002-02-02 00:02:03', '2002-02-02 00:05:03', 'User Title', 2, 1, null, 'keep', 'block', 0), (4, 'a', 3, '2002-02-03 00:02:03', '2002-02-03 00:05:03', 'Rosy Title', 1, 0, 1337, 'meep', 'bloop', 0), (6, 'c', 3, '2002-02-04 00:02:03', '2002-02-04 00:05:03', null, 2, 0, 4400, null, null, 1); - insert into arsse_articles(id,feed,url,title,author,published,edited,modified,guid,url_title_hash,url_content_hash,title_content_hash,content_scraped,content) values + insert into arsse_articles(id, feed, url, title, author, published, edited, modified, guid, url_title_hash, url_content_hash, title_content_hash, content_scraped, content) values (1, 1, 'https://example.com/1', 'Article 1', 'John Doe', '2001-11-08 22:07:55', '2002-11-08 07:51:12', '2001-11-08 23:44:56', 'GUID1', 'UTHASH1', 'UCHASH1', 'TCHASH1', 'Scraped 1', 'Content 1'), (2, 1, 'https://example.com/2', 'Article 2', 'Jane Doe', '2001-11-09 22:07:55', '2002-11-09 07:51:12', '2001-11-09 23:44:56', 'GUID2', 'UTHASH2', 'UCHASH2', 'TCHASH2', 'Scraped 2', 'Content 2'), (3, 2, 'https://example.org/1', 'Article 3', 'John Doe', '2001-11-10 22:07:55', '2002-11-10 07:51:12', '2001-11-10 23:44:56', 'GUID3', 'UTHASH3', 'UCHASH3', 'TCHASH3', 'Scraped 3', 'Content 3'), (4, 2, 'https://example.org/2', 'Article 4', 'Jane Doe', '2001-11-11 22:07:55', '2002-11-11 07:51:12', '2001-11-11 23:44:56', 'GUID4', 'UTHASH4', 'UCHASH4', 'TCHASH4', 'Scraped 4', 'Content 4'), (5, 3, 'https://example.net/1', 'Article 5', 'Adam Doe', '2001-11-12 22:07:55', '2002-11-12 07:51:12', '2001-11-12 23:44:56', 'GUID5', 'UTHASH5', 'UCHASH5', 'TCHASH5', null, 'Content 5'), (6, 3, 'https://example.net/2', 'Article 6', 'Evie Doe', '2001-11-13 22:07:55', '2002-11-13 07:51:12', '2001-11-13 23:44:56', 'GUID6', 'UTHASH6', 'UCHASH6', 'TCHASH6', 'Scraped 6', 'Content 6'); - insert into arsse_marks(article,subscription,"read",starred,modified,note,hidden) values + insert into arsse_marks(article, subscription, "read", starred, modified, note, hidden) values (1, 1, 1, 1, '2002-11-08 00:37:22', 'Note 1', 0), (5, 4, 1, 0, '2002-11-12 00:37:22', 'Note 5', 0), (5, 6, 0, 1, '2002-12-12 00:37:22', '', 0), (6, 6, 0, 0, '2002-12-13 00:37:22', 'Note 6', 1); + insert into arsse_enclosures(article, url, type) values + (2, 'http://example.com/2/enclosure', 'image/png'), + (3, 'http://example.org/3/enclosure', 'image/jpg'), + (4, 'http://example.org/4/enclosure', 'audio/aac'), + (5, 'http://example.net/5/enclosure', 'application/octet-stream'); + insert into arsse_categories(article, name) values + (1, 'Sport'), + (2, 'Opinion'), + (2, 'Gourds'), + (3, 'Politics'), + (6, 'Medicine'), + (6, 'Drugs'), + (6, 'Technology'); + insert into arsse_labels(id, owner, name) values + (1, 'a', 'Follow-up'), + (2, 'a', 'For Gabriel!'), + (3, 'c', 'Maple'), + (4, 'c', 'Brown sugar'); + insert into arsse_label_members(label, article, subscription, assigned, modified) values + (2, 2, 1, 1, '2023-09-01 11:22:33'), + (1, 2, 1, 0, '2023-09-02 11:22:33'), + (1, 5, 4, 1, '2023-09-03 11:22:33'), + (4, 5, 6, 0, '2023-09-04 11:22:33'); QUERY_TEXT ); $this->drv->schemaUpdate(8); @@ -279,8 +302,39 @@ QUERY_TEXT [9, "Content 6"], [10, "Scraped 6"], ] - ] + ], + 'arsse_enclosures' => [ + 'columns' => ["article", "url", "type"], + 'rows' => [ + [2, "http://example.com/2/enclosure", "image/png"], + [7, "http://example.net/5/enclosure", "application/octet-stream"], + [8, "http://example.net/5/enclosure", "application/octet-stream"], + ] + ], + 'arsse_categories' => [ + 'columns' => ["article", "name"], + 'rows' => [ + [1, "Sport"], + [2, "Opinion"], + [2, "Gourds"], + [9, "Medicine"], + [9, "Drugs"], + [9, "Technology"], + [10, "Medicine"], + [10, "Drugs"], + [10, "Technology"], + ] + ], + 'arsse_label_members' => [ + 'columns' => ["label", "article", "assigned", "modified"], + 'rows' => [ + [2, 2, 1, '2023-09-01 11:22:33'], + [1, 2, 0, '2023-09-02 11:22:33'], + [1, 7, 1, '2023-09-03 11:22:33'], + [4, 8, 0, '2023-09-04 11:22:33'], + ] + ] ]; $this->compareExpectations($this->drv, $exp); } -} \ No newline at end of file +}