use separate schema version for tag changes
Will prevent issues if user upgrades after an unclean shutdown
This commit is contained in:
parent
2cff078b50
commit
45ea0ddefd
@ -5,5 +5,6 @@ mod card;
|
||||
mod deckconf;
|
||||
mod sqlite;
|
||||
mod tag;
|
||||
mod upgrades;
|
||||
|
||||
pub(crate) use sqlite::SqliteStorage;
|
||||
|
@ -23,7 +23,7 @@ use unicase::UniCase;
|
||||
|
||||
const SCHEMA_MIN_VERSION: u8 = 11;
|
||||
const SCHEMA_STARTING_VERSION: u8 = 11;
|
||||
const SCHEMA_MAX_VERSION: u8 = 12;
|
||||
const SCHEMA_MAX_VERSION: u8 = 13;
|
||||
|
||||
fn unicase_compare(s1: &str, s2: &str) -> Ordering {
|
||||
UniCase::new(s1).cmp(&UniCase::new(s2))
|
||||
@ -204,35 +204,6 @@ impl SqliteStorage {
|
||||
Ok(storage)
|
||||
}
|
||||
|
||||
fn upgrade_to_latest_schema(&self, ver: u8) -> Result<()> {
|
||||
if ver < 12 {
|
||||
self.upgrade_to_schema_12()?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn downgrade_to_schema_11(self) -> Result<()> {
|
||||
self.begin_trx()?;
|
||||
self.downgrade_from_schema_12()?;
|
||||
self.commit_trx()
|
||||
}
|
||||
|
||||
fn upgrade_to_schema_12(&self) -> Result<()> {
|
||||
self.db
|
||||
.execute_batch(include_str!("schema12_upgrade.sql"))?;
|
||||
self.upgrade_deck_conf_to_schema12()?;
|
||||
self.upgrade_tags_to_schema12()
|
||||
}
|
||||
|
||||
fn downgrade_from_schema_12(&self) -> Result<()> {
|
||||
self.downgrade_tags_from_schema12()?;
|
||||
self.downgrade_deck_conf_from_schema12()?;
|
||||
|
||||
self.db
|
||||
.execute_batch(include_str!("schema12_downgrade.sql"))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// Standard transaction start/stop
|
||||
//////////////////////////////////////
|
||||
|
||||
|
@ -74,7 +74,7 @@ impl SqliteStorage {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(super) fn downgrade_tags_from_schema12(&self) -> Result<()> {
|
||||
pub(super) fn downgrade_tags_from_schema13(&self) -> Result<()> {
|
||||
let alltags = self.all_tags()?;
|
||||
let tagsmap: HashMap<String, Usn> = alltags.into_iter().collect();
|
||||
self.db.execute(
|
||||
|
35
rslib/src/storage/upgrades/mod.rs
Normal file
35
rslib/src/storage/upgrades/mod.rs
Normal file
@ -0,0 +1,35 @@
|
||||
// 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_schema12()?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn downgrade_to_schema_11(self) -> Result<()> {
|
||||
self.begin_trx()?;
|
||||
|
||||
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()
|
||||
}
|
||||
}
|
@ -1,5 +1,4 @@
|
||||
drop table deck_config;
|
||||
drop table tags;
|
||||
update col
|
||||
set
|
||||
ver = 11;
|
@ -5,10 +5,6 @@ create table deck_config (
|
||||
usn integer not null,
|
||||
config text not null
|
||||
);
|
||||
create table tags (
|
||||
tag text not null primary key collate unicase,
|
||||
usn integer not null
|
||||
) without rowid;
|
||||
update col
|
||||
set
|
||||
ver = 12;
|
4
rslib/src/storage/upgrades/schema13_downgrade.sql
Normal file
4
rslib/src/storage/upgrades/schema13_downgrade.sql
Normal file
@ -0,0 +1,4 @@
|
||||
drop table tags;
|
||||
update col
|
||||
set
|
||||
ver = 12;
|
7
rslib/src/storage/upgrades/schema13_upgrade.sql
Normal file
7
rslib/src/storage/upgrades/schema13_upgrade.sql
Normal file
@ -0,0 +1,7 @@
|
||||
create table tags (
|
||||
tag text not null primary key collate unicase,
|
||||
usn integer not null
|
||||
) without rowid;
|
||||
update col
|
||||
set
|
||||
ver = 13;
|
Loading…
Reference in New Issue
Block a user