libchewing
libchewing copied to clipboard
feat(dictionary): support migration from hash.dat to newer db files
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.
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.