mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 06:22:22 -04:00
work around invalid 1.2 decks with multiple templates sharing same ord
This commit is contained in:
parent
7cec4762eb
commit
b5c72155a3
3 changed files with 26 additions and 8 deletions
|
@ -90,9 +90,6 @@ f.id = cards.factId)"""):
|
||||||
if db.list("""
|
if db.list("""
|
||||||
select id from fields where factId not in (select id from facts)"""):
|
select id from fields where factId not in (select id from facts)"""):
|
||||||
return
|
return
|
||||||
# fix ordinal numbers
|
|
||||||
db.execute("""update fields set ordinal = (select ordinal from
|
|
||||||
fieldModels where id = fieldModelId)""")
|
|
||||||
# incorrect types
|
# incorrect types
|
||||||
if db.list("""
|
if db.list("""
|
||||||
select id from cards where relativeDelay != (case
|
select id from cards where relativeDelay != (case
|
||||||
|
@ -129,11 +126,24 @@ fieldModels where id = fieldModelId)""")
|
||||||
db.execute("pragma page_size = 4096")
|
db.execute("pragma page_size = 4096")
|
||||||
db.execute("pragma legacy_file_format = 0")
|
db.execute("pragma legacy_file_format = 0")
|
||||||
|
|
||||||
# previous versions sometimes had cards with incorrect ordinals and
|
for mid in db.list("select id from models"):
|
||||||
# the db check didn't fix that. so we fix it here:
|
# ensure the ordinals are correct for each cardModel
|
||||||
db.execute("""
|
for c, cmid in enumerate(db.list(
|
||||||
update cards set ordinal = (select ordinal from cardModels
|
"select id from cardModels where modelId = ? order by ordinal",
|
||||||
where id = cards.cardModelId)""")
|
mid)):
|
||||||
|
db.execute("update cardModels set ordinal = ? where id = ?",
|
||||||
|
c, cmid)
|
||||||
|
# and fieldModel
|
||||||
|
for c, fmid in enumerate(db.list(
|
||||||
|
"select id from fieldModels where modelId = ? order by ordinal",
|
||||||
|
mid)):
|
||||||
|
db.execute("update fieldModels set ordinal = ? where id = ?",
|
||||||
|
c, fmid)
|
||||||
|
# then fix ordinals numbers on cards & fields
|
||||||
|
db.execute("""update cards set ordinal = (select ordinal from
|
||||||
|
cardModels where cardModels.id = cardModelId)""")
|
||||||
|
db.execute("""update fields set ordinal = (select ordinal from
|
||||||
|
fieldModels where id = fieldModelId)""")
|
||||||
|
|
||||||
# notes
|
# notes
|
||||||
###########
|
###########
|
||||||
|
|
BIN
tests/support/invalid-ords.anki
Normal file
BIN
tests/support/invalid-ords.anki
Normal file
Binary file not shown.
|
@ -49,6 +49,14 @@ def test_upgrade1_due():
|
||||||
deck = u.upgrade(dst)
|
deck = u.upgrade(dst)
|
||||||
assert not deck.db.scalar("select 1 from cards where due != 1")
|
assert not deck.db.scalar("select 1 from cards where due != 1")
|
||||||
|
|
||||||
|
def test_invalid_ords():
|
||||||
|
dst = getUpgradeDeckPath("invalid-ords.anki")
|
||||||
|
u = Upgrader()
|
||||||
|
u.check(dst)
|
||||||
|
deck = u.upgrade(dst)
|
||||||
|
assert deck.db.scalar("select count() from cards where ord = 0") == 1
|
||||||
|
assert deck.db.scalar("select count() from cards where ord = 1") == 1
|
||||||
|
|
||||||
def test_upgrade2():
|
def test_upgrade2():
|
||||||
p = "/tmp/alpha-upgrade.anki2"
|
p = "/tmp/alpha-upgrade.anki2"
|
||||||
if os.path.exists(p):
|
if os.path.exists(p):
|
||||||
|
|
Loading…
Reference in a new issue