libchewing icon indicating copy to clipboard operation
libchewing copied to clipboard

feat(dictionary): support migration from hash.dat to newer db files

Open kanru opened this issue 2 years ago • 1 comments

There are several existing user dictionary format supported by libchewing.

After switching to libchewing-rs we should automatically migrate all of them to the current format, then we can deprecate old formats.

kanru avatar Dec 31 '23 09:12 kanru

Previously supported user dictionary file and format:

  • uhash.dat (text)
  • uhash.dat (bin)
  • chewing.sqlite (sqlite)

Current available user dictionary backend

  • sqlite
  • cdb

Algorithm for selecting new backend

if (has_sqlite) return use_sqlite
if (has_cdb) return use_cdb
return error or in memory db

Migration algorithm

let new_db = new_db_backend()
if (uhash_exists || cdb_exists) {
  migrate_to_new_db_backend()
  rename_uhash_to_uhash_bak()
}

sqlite backend can be migrated in place. If sqlite backend is available then we don't need to do migration. If sqlite backend is not available then we can't read so there's no way to migrate to other backend.

kanru avatar Feb 25 '24 03:02 kanru