Anki/rslib/src/storage/upgrades/mod.rs
Damien Elmes 676f4e74a8 store config in separate DB table
- mtime is tracked on each key individually, which will allow
merging of config changes when syncing in the future
- added col.(get|set|remove)_config()
- in order to support existing code that was mutating returned
values (eg col.conf["something"]["another"] = 5), the returned list/dict
will be automatically wrapped so that when the value is dropped, it
will save the mutated item back to the DB if it's changed. Code that
is fetching lists/dicts from the config like so:

col.conf["foo"]["bar"] = baz
col.setMod()

will continue to work in most case, but should be gradually updated to:

conf = col.get_config("foo")
conf["bar"] = baz
col.set_config("foo", conf)
2020-04-06 15:39:47 +10:00

47 lines
1.3 KiB
Rust

// Copyright: Ankitects Pty Ltd and contributors
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
use super::SqliteStorage;
use crate::err::Result;
impl SqliteStorage {
pub(super) fn upgrade_to_latest_schema(&self, ver: u8) -> Result<()> {
if ver < 12 {
self.db
.execute_batch(include_str!("schema12_upgrade.sql"))?;
self.upgrade_deck_conf_to_schema12()?;
}
if ver < 13 {
self.db
.execute_batch(include_str!("schema13_upgrade.sql"))?;
self.upgrade_tags_to_schema13()?;
}
if ver < 14 {
self.db
.execute_batch(include_str!("schema14_upgrade.sql"))?;
self.upgrade_config_to_schema14()?;
}
Ok(())
}
pub(super) fn downgrade_to_schema_11(&self) -> Result<()> {
self.begin_trx()?;
self.downgrade_config_from_schema14()?;
self.db
.execute_batch(include_str!("schema14_downgrade.sql"))?;
self.downgrade_tags_from_schema13()?;
self.db
.execute_batch(include_str!("schema13_downgrade.sql"))?;
self.downgrade_deck_conf_from_schema12()?;
self.db
.execute_batch(include_str!("schema12_downgrade.sql"))?;
self.commit_trx()?;
Ok(())
}
}