merge the 12-14 upgrade code

This commit is contained in:
Damien Elmes 2020-04-10 10:52:31 +10:00
parent c79b6835bf
commit bbceeacf0b
9 changed files with 22 additions and 48 deletions

View File

@ -90,7 +90,7 @@ impl SqliteStorage {
self.add_deck_conf(&mut conf)
}
pub(super) fn upgrade_deck_conf_to_schema12(&self) -> Result<()> {
pub(super) fn upgrade_deck_conf_to_schema14(&self) -> Result<()> {
let conf = self
.db
.query_row_and_then("select dconf from col", NO_PARAMS, |row| {
@ -106,7 +106,7 @@ impl SqliteStorage {
Ok(())
}
pub(super) fn downgrade_deck_conf_from_schema12(&self) -> Result<()> {
pub(super) fn downgrade_deck_conf_from_schema14(&self) -> Result<()> {
let allconf = self.all_deck_config()?;
let confmap: HashMap<DeckConfID, DeckConf> =
allconf.into_iter().map(|c| (c.id, c)).collect();

View File

@ -58,7 +58,7 @@ impl SqliteStorage {
// Upgrading/downgrading
pub(super) fn upgrade_tags_to_schema13(&self) -> Result<()> {
pub(super) fn upgrade_tags_to_schema14(&self) -> Result<()> {
let tags = self
.db
.query_row_and_then("select tags from col", NO_PARAMS, |row| {
@ -74,7 +74,7 @@ impl SqliteStorage {
Ok(())
}
pub(super) fn downgrade_tags_from_schema13(&self) -> Result<()> {
pub(super) fn downgrade_tags_from_schema14(&self) -> Result<()> {
let alltags = self.all_tags()?;
let tagsmap: HashMap<String, Usn> = alltags.into_iter().collect();
self.db.execute(

View File

@ -6,19 +6,11 @@ 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_deck_conf_to_schema14()?;
self.upgrade_tags_to_schema14()?;
self.upgrade_config_to_schema14()?;
}
@ -29,16 +21,10 @@ impl SqliteStorage {
self.begin_trx()?;
self.downgrade_config_from_schema14()?;
self.downgrade_tags_from_schema14()?;
self.downgrade_deck_conf_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"))?;
.execute_batch(include_str!("schema11_downgrade.sql"))?;
self.commit_trx()?;

View File

@ -1,4 +1,6 @@
drop table config;
drop table deck_config;
drop table tags;
update col
set
ver = 11;

View File

@ -1,10 +0,0 @@
create table deck_config (
id integer primary key not null,
name text not null collate unicase,
mtime_secs integer not null,
usn integer not null,
config blob not null
);
update col
set
ver = 12;

View File

@ -1,4 +0,0 @@
drop table tags;
update col
set
ver = 12;

View File

@ -1,7 +0,0 @@
create table tags (
tag text not null primary key collate unicase,
usn integer not null
) without rowid;
update col
set
ver = 13;

View File

@ -1,4 +0,0 @@
drop table config;
update col
set
ver = 13;

View File

@ -1,9 +1,20 @@
create table deck_config (
id integer primary key not null,
name text not null collate unicase,
mtime_secs integer not null,
usn integer not null,
config blob not null
);
create table config (
key text not null primary key,
usn integer not null,
mtime_secs integer not null,
val blob not null
) without rowid;
create table tags (
tag text not null primary key collate unicase,
usn integer not null
) without rowid;
update col
set
ver = 14;