catch incorrect ordinals on upgrade

This commit is contained in:
Damien Elmes 2011-11-28 16:57:58 +09:00
parent cd76706a2f
commit bd29318168
2 changed files with 18 additions and 12 deletions

View file

@ -21,7 +21,7 @@ class CardStats(object):
def report(self): def report(self):
c = self.card c = self.card
fmt = lambda x, **kwargs: fmtTimeSpan(x, short=True, **kwargs) fmt = lambda x, **kwargs: fmtTimeSpan(x, short=True, **kwargs)
self.txt = "<table width=100%%>" self.txt = "<table width=100%>"
self.addLine(_("Added"), self.date(c.id/1000)) self.addLine(_("Added"), self.date(c.id/1000))
first = self.col.db.scalar( first = self.col.db.scalar(
"select min(id) from revlog where cid = ?", c.id) "select min(id) from revlog where cid = ?", c.id)

View file

@ -60,29 +60,35 @@ create index if not exists ix_fields_factId on fieldModels (factId);
analyze;""") analyze;""")
# fields missing a field model? # fields missing a field model?
if db.list(""" if db.list("""
select id from fields where fieldModelId not in ( select id from fields where fieldModelId not in (
select distinct id from fieldModels)"""): select distinct id from fieldModels)"""):
return return
# facts missing a field? # facts missing a field?
if db.list(""" if db.list("""
select distinct facts.id from facts, fieldModels where select distinct facts.id from facts, fieldModels where
facts.modelId = fieldModels.modelId and fieldModels.id not in facts.modelId = fieldModels.modelId and fieldModels.id not in
(select fieldModelId from fields where factId = facts.id)"""): (select fieldModelId from fields where factId = facts.id)"""):
return return
# cards missing a fact? # cards missing a fact?
if db.list(""" if db.list("""
select id from cards where factId not in (select id from facts)"""): select id from cards where factId not in (select id from facts)"""):
return return
# cards missing a card model? # cards missing a card model?
if db.list(""" if db.list("""
select id from cards where cardModelId not in select id from cards where cardModelId not in
(select id from cardModels)"""): (select id from cardModels)"""):
return return
# cards with a card model from the wrong model? # cards with a card model from the wrong model?
if db.list(""" if db.list("""
select id from cards where cardModelId not in (select cm.id from select id from cards where cardModelId not in (select cm.id from
cardModels cm, facts f where cm.modelId = f.modelId and cardModels cm, facts f where cm.modelId = f.modelId and
f.id = cards.factId)"""): f.id = cards.factId)"""):
return
# cards with the wrong ordinal?
if db.list("""
select c.id from cards c, cardModels cm
where c.cardModelId = cm.id
and c.ordinal != cm.ordinal"""):
return return
# facts missing a card? # facts missing a card?
if db.list(""" if db.list("""