Add code to migrate database model
Add code to migrate database model when `authors` column is not present in the index This recreates `search` table and resets the articles index Added missing or code in error
This commit is contained in:
parent
5636ca0a01
commit
cf1be33044
@ -63,6 +63,7 @@ public final class ArticlesDatabase {
|
||||
}
|
||||
|
||||
private let articlesTable: ArticlesTable
|
||||
private let searchTable: SearchTable
|
||||
private let queue: DatabaseQueue
|
||||
private let operationQueue = MainThreadOperationQueue()
|
||||
private let retentionStyle: RetentionStyle
|
||||
@ -71,6 +72,7 @@ public final class ArticlesDatabase {
|
||||
let queue = DatabaseQueue(databasePath: databaseFilePath)
|
||||
self.queue = queue
|
||||
self.articlesTable = ArticlesTable(name: DatabaseTableName.articles, accountID: accountID, queue: queue, retentionStyle: retentionStyle)
|
||||
self.searchTable = SearchTable(queue: queue, articlesTable: self.articlesTable)
|
||||
self.retentionStyle = retentionStyle
|
||||
|
||||
try! queue.runCreateStatements(ArticlesDatabase.tableCreationStatements)
|
||||
@ -81,6 +83,9 @@ public final class ArticlesDatabase {
|
||||
}
|
||||
database.executeStatements("CREATE INDEX if not EXISTS articles_searchRowID on articles(searchRowID);")
|
||||
database.executeStatements("DROP TABLE if EXISTS tags;DROP INDEX if EXISTS tags_tagName_index;DROP INDEX if EXISTS articles_feedID_index;DROP INDEX if EXISTS statuses_read_index;DROP TABLE if EXISTS attachments;DROP TABLE if EXISTS attachmentsLookup;")
|
||||
if !self.searchTable.containsColumn("authors", in: database) {
|
||||
database.executeStatements("DROP TABLE if EXISTS search;CREATE VIRTUAL TABLE if not EXISTS search using fts4(title, body, authors);UPDATE articles SET searchRowID = null;")
|
||||
}
|
||||
}
|
||||
|
||||
DispatchQueue.main.async {
|
||||
|
@ -158,8 +158,8 @@ final class ArticlesTable: DatabaseTable {
|
||||
art.contentText,
|
||||
art.summary,
|
||||
art.searchRowID,
|
||||
(SELECT GROUP_CONCAT(name SEPARATOR ' ')
|
||||
FROM authorLookup as autL
|
||||
(SELECT GROUP_CONCAT(name, ' ')
|
||||
FROM authorsLookup as autL
|
||||
JOIN authors as aut ON autL.authorID = aut.authorID
|
||||
WHERE art.articleID = autL.articleID
|
||||
GROUP BY autl.articleID) as authors
|
||||
|
@ -61,7 +61,7 @@ final class ArticleSearchInfo: Hashable {
|
||||
// MARK: Equatable
|
||||
|
||||
static func == (lhs: ArticleSearchInfo, rhs: ArticleSearchInfo) -> Bool {
|
||||
return lhs.articleID == rhs.articleID && lhs.title == rhs.title && lhs.contentHTML == rhs.contentHTML && lhs.contentText == rhs.contentText && lhs.summary == rhs.summary && lhs.searchRowID == rhs.searchRowID
|
||||
return lhs.articleID == rhs.articleID && lhs.title == rhs.title && lhs.authorsNames == rhs.authorsNames && lhs.contentHTML == rhs.contentHTML && lhs.contentText == rhs.contentText && lhs.summary == rhs.summary && lhs.searchRowID == rhs.searchRowID
|
||||
}
|
||||
}
|
||||
|
||||
@ -203,7 +203,7 @@ private extension SearchTable {
|
||||
return nil
|
||||
}
|
||||
let placeholders = NSString.rs_SQLValueList(withPlaceholders: UInt(searchRowIDs.count))!
|
||||
let sql = "select rowid, title, body from \(name) where rowid in \(placeholders);"
|
||||
let sql = "select rowid, title, body, authors from \(name) where rowid in \(placeholders);"
|
||||
guard let resultSet = database.executeQuery(sql, withArgumentsIn: searchRowIDs) else {
|
||||
return nil
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user