Fix DB integrity check when there's only one of a given problem
This commit is contained in:
parent
810e0a3239
commit
1cb49cc5d3
1 changed files with 10 additions and 10 deletions
|
@ -1285,54 +1285,54 @@ Zotero.Schema = new function(){
|
|||
var checks = [
|
||||
// Can't be a FK with itemTypesCombined
|
||||
[
|
||||
"SELECT COUNT(*) > 1 FROM items WHERE itemTypeID IS NULL",
|
||||
"SELECT COUNT(*) > 0 FROM items WHERE itemTypeID IS NULL",
|
||||
"DELETE FROM items WHERE itemTypeID IS NULL",
|
||||
],
|
||||
// Attachments row with itemTypeID != 14
|
||||
[
|
||||
"SELECT COUNT(*) > 1 FROM itemAttachments JOIN items USING (itemID) WHERE itemTypeID != 14",
|
||||
"SELECT COUNT(*) > 0 FROM itemAttachments JOIN items USING (itemID) WHERE itemTypeID != 14",
|
||||
"UPDATE items SET itemTypeID=14, clientDateModified=CURRENT_TIMESTAMP WHERE itemTypeID != 14 AND itemID IN (SELECT itemID FROM itemAttachments)",
|
||||
],
|
||||
// Fields not in type
|
||||
[
|
||||
"SELECT COUNT(*) > 1 FROM itemData WHERE fieldID NOT IN (SELECT fieldID FROM itemTypeFieldsCombined WHERE itemTypeID=(SELECT itemTypeID FROM items WHERE itemID=itemData.itemID))",
|
||||
"SELECT COUNT(*) > 0 FROM itemData WHERE fieldID NOT IN (SELECT fieldID FROM itemTypeFieldsCombined WHERE itemTypeID=(SELECT itemTypeID FROM items WHERE itemID=itemData.itemID))",
|
||||
"DELETE FROM itemData WHERE fieldID NOT IN (SELECT fieldID FROM itemTypeFieldsCombined WHERE itemTypeID=(SELECT itemTypeID FROM items WHERE itemID=itemData.itemID))",
|
||||
],
|
||||
// Missing itemAttachments row
|
||||
[
|
||||
"SELECT COUNT(*) > 1 FROM items WHERE itemTypeID=14 AND itemID NOT IN (SELECT itemID FROM itemAttachments)",
|
||||
"SELECT COUNT(*) > 0 FROM items WHERE itemTypeID=14 AND itemID NOT IN (SELECT itemID FROM itemAttachments)",
|
||||
"INSERT INTO itemAttachments (itemID, linkMode) SELECT itemID, 0 FROM items WHERE itemTypeID=14 AND itemID NOT IN (SELECT itemID FROM itemAttachments)",
|
||||
],
|
||||
// Note/child parents
|
||||
[
|
||||
"SELECT COUNT(*) > 1 FROM itemAttachments WHERE parentItemID IN (SELECT itemID FROM items WHERE itemTypeID IN (1,14))",
|
||||
"SELECT COUNT(*) > 0 FROM itemAttachments WHERE parentItemID IN (SELECT itemID FROM items WHERE itemTypeID IN (1,14))",
|
||||
"UPDATE itemAttachments SET parentItemID=NULL WHERE parentItemID IN (SELECT itemID FROM items WHERE itemTypeID IN (1,14))",
|
||||
],
|
||||
[
|
||||
"SELECT COUNT(*) > 1 FROM itemNotes WHERE parentItemID IN (SELECT itemID FROM items WHERE itemTypeID IN (1,14))",
|
||||
"SELECT COUNT(*) > 0 FROM itemNotes WHERE parentItemID IN (SELECT itemID FROM items WHERE itemTypeID IN (1,14))",
|
||||
"UPDATE itemNotes SET parentItemID=NULL WHERE parentItemID IN (SELECT itemID FROM items WHERE itemTypeID IN (1,14))",
|
||||
],
|
||||
|
||||
// Delete empty creators
|
||||
// This may cause itemCreator gaps, but that's better than empty creators
|
||||
[
|
||||
"SELECT COUNT(*) > 1 FROM creators WHERE firstName='' AND lastName=''",
|
||||
"SELECT COUNT(*) > 0 FROM creators WHERE firstName='' AND lastName=''",
|
||||
"DELETE FROM creators WHERE firstName='' AND lastName=''"
|
||||
],
|
||||
|
||||
// Non-attachment items in the full-text index
|
||||
[
|
||||
"SELECT COUNT(*) > 1 FROM fulltextItemWords WHERE itemID NOT IN (SELECT itemID FROM items WHERE itemTypeID=14)",
|
||||
"SELECT COUNT(*) > 0 FROM fulltextItemWords WHERE itemID NOT IN (SELECT itemID FROM items WHERE itemTypeID=14)",
|
||||
"DELETE FROM fulltextItemWords WHERE itemID NOT IN (SELECT itemID FROM items WHERE itemTypeID=14)"
|
||||
],
|
||||
// Full-text items must be attachments
|
||||
[
|
||||
"SELECT COUNT(*) > 1 FROM fulltextItems WHERE itemID NOT IN (SELECT itemID FROM items WHERE itemTypeID=14)",
|
||||
"SELECT COUNT(*) > 0 FROM fulltextItems WHERE itemID NOT IN (SELECT itemID FROM items WHERE itemTypeID=14)",
|
||||
"DELETE FROM fulltextItems WHERE itemID NOT IN (SELECT itemID FROM items WHERE itemTypeID=14)"
|
||||
],
|
||||
// Invalid link mode -- set to imported url
|
||||
[
|
||||
"SELECT COUNT(*) > 1 FROM itemAttachments WHERE linkMode NOT IN (0,1,2,3)",
|
||||
"SELECT COUNT(*) > 0 FROM itemAttachments WHERE linkMode NOT IN (0,1,2,3)",
|
||||
"UPDATE itemAttachments SET linkMode=1 WHERE linkMode NOT IN (0,1,2,3)"
|
||||
]
|
||||
];
|
||||
|
|
Loading…
Reference in a new issue