on upgrade all cards of a note should share the same due #

This commit is contained in:
Damien Elmes 2012-04-06 12:45:01 +09:00
parent 5c59f6a558
commit aa559431b6
4 changed files with 10 additions and 22 deletions

View file

@ -624,24 +624,6 @@ and ord = ? limit 1""", m['id'], t['ord']):
f['name'], tmpl['qfmt'], f['name'])
return True
# New due times
######################################################################
# New cards now use a user-friendly increasing integer rather than a
# timestamp
def _rewriteNewDue(self):
col = self.col
pos = 0
data = []
for id, due in col.db.execute(
"select id, due from cards where type = 0 order by id"):
pos += 1
data.append((pos, id))
col.db.executemany("update cards set due = ? where id = ?", data)
# update insertion id
col.conf['nextPos'] = pos + 1
col.save()
# Post-schema upgrade
######################################################################
@ -683,8 +665,6 @@ and ord = ? limit 1""", m['id'], t['ord']):
# remove old deleted tables
for t in ("cards", "notes", "models", "media"):
col.db.execute("drop table if exists %sDeleted" % t)
# rewrite due times for new cards
self._rewriteNewDue()
# and failed cards
left = len(col.decks.confForDid(1)['new']['delays'])
col.db.execute("update cards set odue = ?, left=? where type = 1",
@ -704,6 +684,8 @@ update cards set due = cast(
conf = col.decks.allConf()[0]
if not conf['new']['order']:
col.sched.randomizeCards(1)
else:
col.sched.orderCards(1)
# optimize and finish
col.db.commit()
col.db.execute("vacuum")

View file

@ -14,8 +14,8 @@ def getEmptyDeck(**kwargs):
os.unlink(nam)
return aopen(nam, **kwargs)
def getUpgradeDeckPath():
src = os.path.join(testDir, "support", "anki12.anki")
def getUpgradeDeckPath(name="anki12.anki"):
src = os.path.join(testDir, "support", name)
(fd, dst) = tempfile.mkstemp(suffix=".anki2")
shutil.copy(src, dst)
return dst

Binary file not shown.

View file

@ -43,6 +43,12 @@ def test_upgrade1():
# print
# print "--a", c.a()
def test_upgrade1_due():
dst = getUpgradeDeckPath("anki12-due.anki")
u = Upgrader()
deck = u.upgrade(dst)
print deck.db.all("select nid, due from cards")
def test_upgrade2():
p = "/tmp/alpha-upgrade.anki2"
if os.path.exists(p):