Skip to content

Read Anki 2.1.49+ split-table schema (notetypes/templates/fields/deck_config/config/tags) #2

@wpwilson10

Description

@wpwilson10

Problem

Anki 2.1.49+ stores collection metadata in separate SQLite tables (notetypes, templates, fields, deck_config, config, tags) and leaves the legacy col.{models,decks,conf,dconf,tags} JSON columns as empty strings. spacedrep currently reads only the legacy col.* JSONs, so any collection produced by recent Anki Desktop (or exported without "Support older Anki versions" checked) is rejected with UnsupportedCollectionFormatError instead of being usable.

The error was added in the previous patch so the failure is at least actionable — users get a clear message pointing them to re-export in the legacy format. This issue tracks the underlying compatibility work.

Scope sketch

  • Read path: load note-type/template/field metadata from notetypes + templates + fields, decks from decks + deck_config, config from config, tags from tags. Feed these into the existing ColMeta / ModelInfo shapes so the rest of the code doesn't need to branch.
  • Write path: mirror writes into the new tables (or the DB diverges from what Anki expects on re-open). This is the harder half — it's a read + write project, not just a reader.
  • Detection: db.is_modern_anki_schema(conn) already identifies these DBs; the boundary checks in core._open_db / core.open_deck would become "use the modern reader" instead of "raise".

Design notes

  • Model IDs and shapes differ between col.models JSON (Anki ≤2.1.48) and the notetypes/templates/fields row layout — a translation layer will be needed.
  • col.ver is likely the cleanest runtime signal for which schema the DB uses; confirm before relying on it.
  • Consider whether spacedrep db init should produce legacy-format or modern-format DBs once support lands; probably legacy for simplicity until the modern writer is complete.

Repro

# Any collection.anki21 from recent Anki Desktop:
spacedrep card list --db /path/to/collection.anki21
# => {"error": "unsupported_collection_format", ...}

Workaround today

Export from Anki Desktop as an .apkg with "Support older Anki versions" checked (File → Export), then spacedrep deck import the resulting .apkg.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions