mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
set the new types on upgrade
This commit is contained in:
parent
22a72d82c6
commit
368bdf8d05
4 changed files with 18 additions and 6 deletions
|
@ -441,7 +441,7 @@ select id from facts where tags like :_tag_%d""" % c
|
||||||
"from deckvars where key = 'leechFails')")
|
"from deckvars where key = 'leechFails')")
|
||||||
else: # due
|
else: # due
|
||||||
qquery += ("select id from cards where "
|
qquery += ("select id from cards where "
|
||||||
"queue between 0 and 1 and due < %d") % deck.dayCutoff
|
"queue = 2 and due <= %d") % deck.sched.today
|
||||||
elif type == SEARCH_FID:
|
elif type == SEARCH_FID:
|
||||||
if fidquery:
|
if fidquery:
|
||||||
if isNeg:
|
if isNeg:
|
||||||
|
|
|
@ -243,10 +243,20 @@ def _upgradeSchema(db):
|
||||||
_moveTable(db, "cards", True)
|
_moveTable(db, "cards", True)
|
||||||
# use the new order to rewrite card ids
|
# use the new order to rewrite card ids
|
||||||
cardmap = dict(db.all("select id, rowid from cards2"))
|
cardmap = dict(db.all("select id, rowid from cards2"))
|
||||||
# move back, preserving new ids
|
# move back, preserving new ids, and rewriting types
|
||||||
db.execute("""
|
db.execute("""
|
||||||
insert into cards select rowid, factId, 1, ordinal, cast(created as int),
|
insert into cards select rowid, factId, 1, ordinal, cast(created as int),
|
||||||
cast(modified as int), relativeDelay, type, due, cast(interval as int),
|
cast(modified as int),
|
||||||
|
(case relativeDelay
|
||||||
|
when 0 then 1
|
||||||
|
when 1 then 2
|
||||||
|
when 2 then 0 end),
|
||||||
|
(case type
|
||||||
|
when 0 then 1
|
||||||
|
when 1 then 2
|
||||||
|
when 2 then 0
|
||||||
|
else type end),
|
||||||
|
due, cast(interval as int),
|
||||||
cast(factor*1000 as int), reps, successive, noCount, 0, 0, 0, "" from cards2
|
cast(factor*1000 as int), reps, successive, noCount, 0, 0, 0, "" from cards2
|
||||||
order by created""")
|
order by created""")
|
||||||
db.execute("drop table cards2")
|
db.execute("drop table cards2")
|
||||||
|
@ -505,15 +515,15 @@ def _postSchemaUpgrade(deck):
|
||||||
deck.db.execute("drop table if exists %sDeleted" % t)
|
deck.db.execute("drop table if exists %sDeleted" % t)
|
||||||
# rewrite due times for new cards
|
# rewrite due times for new cards
|
||||||
deck.db.execute("""
|
deck.db.execute("""
|
||||||
update cards set due = fid where type=2""")
|
update cards set due = fid where type=0""")
|
||||||
# and failed cards
|
# and failed cards
|
||||||
deck.db.execute("update cards set edue = ? where type = 0",
|
deck.db.execute("update cards set edue = ? where type = 1",
|
||||||
deck.sched.today+1)
|
deck.sched.today+1)
|
||||||
# and due cards
|
# and due cards
|
||||||
deck.db.execute("""
|
deck.db.execute("""
|
||||||
update cards set due = cast(
|
update cards set due = cast(
|
||||||
(case when due < :stamp then 0 else 1 end) +
|
(case when due < :stamp then 0 else 1 end) +
|
||||||
((due-:stamp)/86400) as int)+:today where type = 1
|
((due-:stamp)/86400) as int)+:today where type = 2
|
||||||
""", stamp=deck.sched.dayCutoff, today=deck.sched.today)
|
""", stamp=deck.sched.dayCutoff, today=deck.sched.today)
|
||||||
# update insertion id
|
# update insertion id
|
||||||
deck.conf['nextFid'] = deck.db.scalar("select max(id) from facts")+1
|
deck.conf['nextFid'] = deck.db.scalar("select max(id) from facts")+1
|
||||||
|
|
Binary file not shown.
|
@ -121,6 +121,8 @@ def test_upgrade():
|
||||||
print "upgrade to", dst
|
print "upgrade to", dst
|
||||||
shutil.copy(src, dst)
|
shutil.copy(src, dst)
|
||||||
deck = Deck(dst)
|
deck = Deck(dst)
|
||||||
|
# 3 new, 2 failed, 1 due
|
||||||
|
assert deck.sched.counts() == (3,2,1)
|
||||||
# now's a good time to test the integrity check too
|
# now's a good time to test the integrity check too
|
||||||
deck.fixIntegrity()
|
deck.fixIntegrity()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue