Fix upgrade error on duplicate creatorData rows
This commit is contained in:
parent
0ce45103bb
commit
fb6cf4f9a9
1 changed files with 6 additions and 0 deletions
|
@ -2046,6 +2046,12 @@ Zotero.Schema = new function(){
|
|||
yield Zotero.DB.queryAsync("INSERT OR IGNORE INTO items SELECT itemID, itemTypeID, dateAdded, dateModified, clientDateModified, IFNULL(libraryID, 1), key, 0, 0 FROM itemsOld ORDER BY dateAdded DESC");
|
||||
yield Zotero.DB.queryAsync("CREATE INDEX items_synced ON items(synced)");
|
||||
|
||||
let rows = yield Zotero.DB.queryAsync("SELECT firstName, lastName, fieldMode, COUNT(*) FROM creatorData GROUP BY firstName, lastName, fieldMode HAVING COUNT(*) > 1");
|
||||
for (let row of rows) {
|
||||
let ids = yield Zotero.DB.columnQueryAsync("SELECT creatorDataID FROM creatorData WHERE firstName=? AND lastName=? AND fieldMode=?", [row.firstName, row.lastName, row.fieldMode]);
|
||||
yield Zotero.DB.queryAsync("UPDATE creators SET creatorDataID=" + ids[0] + " WHERE creatorDataID IN (" + ids.slice(1).join(", ") + ")");
|
||||
}
|
||||
yield Zotero.DB.queryAsync("DELETE FROM creatorData WHERE creatorDataID NOT IN (SELECT creatorDataID FROM creators)");
|
||||
yield Zotero.DB.queryAsync("ALTER TABLE creators RENAME TO creatorsOld");
|
||||
yield Zotero.DB.queryAsync("CREATE TABLE creators (\n creatorID INTEGER PRIMARY KEY,\n firstName TEXT,\n lastName TEXT,\n fieldMode INT,\n UNIQUE (lastName, firstName, fieldMode)\n)");
|
||||
yield Zotero.DB.queryAsync("INSERT INTO creators SELECT creatorDataID, firstName, lastName, fieldMode FROM creatorData");
|
||||
|
|
Loading…
Reference in a new issue