mirror of
https://github.com/ankitects/anki.git
synced 2025-11-14 16:47:12 -05:00
merge the 12-14 upgrade code
This commit is contained in:
parent
c79b6835bf
commit
bbceeacf0b
9 changed files with 22 additions and 48 deletions
|
|
@ -90,7 +90,7 @@ impl SqliteStorage {
|
||||||
self.add_deck_conf(&mut conf)
|
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
|
let conf = self
|
||||||
.db
|
.db
|
||||||
.query_row_and_then("select dconf from col", NO_PARAMS, |row| {
|
.query_row_and_then("select dconf from col", NO_PARAMS, |row| {
|
||||||
|
|
@ -106,7 +106,7 @@ impl SqliteStorage {
|
||||||
Ok(())
|
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 allconf = self.all_deck_config()?;
|
||||||
let confmap: HashMap<DeckConfID, DeckConf> =
|
let confmap: HashMap<DeckConfID, DeckConf> =
|
||||||
allconf.into_iter().map(|c| (c.id, c)).collect();
|
allconf.into_iter().map(|c| (c.id, c)).collect();
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ impl SqliteStorage {
|
||||||
|
|
||||||
// Upgrading/downgrading
|
// Upgrading/downgrading
|
||||||
|
|
||||||
pub(super) fn upgrade_tags_to_schema13(&self) -> Result<()> {
|
pub(super) fn upgrade_tags_to_schema14(&self) -> Result<()> {
|
||||||
let tags = self
|
let tags = self
|
||||||
.db
|
.db
|
||||||
.query_row_and_then("select tags from col", NO_PARAMS, |row| {
|
.query_row_and_then("select tags from col", NO_PARAMS, |row| {
|
||||||
|
|
@ -74,7 +74,7 @@ impl SqliteStorage {
|
||||||
Ok(())
|
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 alltags = self.all_tags()?;
|
||||||
let tagsmap: HashMap<String, Usn> = alltags.into_iter().collect();
|
let tagsmap: HashMap<String, Usn> = alltags.into_iter().collect();
|
||||||
self.db.execute(
|
self.db.execute(
|
||||||
|
|
|
||||||
|
|
@ -6,19 +6,11 @@ use crate::err::Result;
|
||||||
|
|
||||||
impl SqliteStorage {
|
impl SqliteStorage {
|
||||||
pub(super) fn upgrade_to_latest_schema(&self, ver: u8) -> Result<()> {
|
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 {
|
if ver < 14 {
|
||||||
self.db
|
self.db
|
||||||
.execute_batch(include_str!("schema14_upgrade.sql"))?;
|
.execute_batch(include_str!("schema14_upgrade.sql"))?;
|
||||||
|
self.upgrade_deck_conf_to_schema14()?;
|
||||||
|
self.upgrade_tags_to_schema14()?;
|
||||||
self.upgrade_config_to_schema14()?;
|
self.upgrade_config_to_schema14()?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -29,16 +21,10 @@ impl SqliteStorage {
|
||||||
self.begin_trx()?;
|
self.begin_trx()?;
|
||||||
|
|
||||||
self.downgrade_config_from_schema14()?;
|
self.downgrade_config_from_schema14()?;
|
||||||
|
self.downgrade_tags_from_schema14()?;
|
||||||
|
self.downgrade_deck_conf_from_schema14()?;
|
||||||
self.db
|
self.db
|
||||||
.execute_batch(include_str!("schema14_downgrade.sql"))?;
|
.execute_batch(include_str!("schema11_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()?;
|
self.commit_trx()?;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
|
drop table config;
|
||||||
drop table deck_config;
|
drop table deck_config;
|
||||||
|
drop table tags;
|
||||||
update col
|
update col
|
||||||
set
|
set
|
||||||
ver = 11;
|
ver = 11;
|
||||||
|
|
@ -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;
|
|
||||||
|
|
@ -1,4 +0,0 @@
|
||||||
drop table tags;
|
|
||||||
update col
|
|
||||||
set
|
|
||||||
ver = 12;
|
|
||||||
|
|
@ -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;
|
|
||||||
|
|
@ -1,4 +0,0 @@
|
||||||
drop table config;
|
|
||||||
update col
|
|
||||||
set
|
|
||||||
ver = 13;
|
|
||||||
|
|
@ -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 (
|
create table config (
|
||||||
key text not null primary key,
|
key text not null primary key,
|
||||||
usn integer not null,
|
usn integer not null,
|
||||||
mtime_secs integer not null,
|
mtime_secs integer not null,
|
||||||
val blob not null
|
val blob not null
|
||||||
) without rowid;
|
) without rowid;
|
||||||
|
create table tags (
|
||||||
|
tag text not null primary key collate unicase,
|
||||||
|
usn integer not null
|
||||||
|
) without rowid;
|
||||||
update col
|
update col
|
||||||
set
|
set
|
||||||
ver = 14;
|
ver = 14;
|
||||||
Loading…
Reference in a new issue