diff --git a/rslib/src/storage/graves/mod.rs b/rslib/src/storage/graves/mod.rs index b8d9c0021..468ea2811 100644 --- a/rslib/src/storage/graves/mod.rs +++ b/rslib/src/storage/graves/mod.rs @@ -72,7 +72,6 @@ impl SqliteStorage { Ok(graves) } - // fixme: graves is missing an index pub(crate) fn update_pending_grave_usns(&self, new_usn: Usn) -> Result<()> { self.db .prepare("update graves set usn=? where usn=-1")? diff --git a/rslib/src/storage/upgrades/mod.rs b/rslib/src/storage/upgrades/mod.rs index cb2b2ac81..6e9fe5b82 100644 --- a/rslib/src/storage/upgrades/mod.rs +++ b/rslib/src/storage/upgrades/mod.rs @@ -6,7 +6,7 @@ pub(super) const SCHEMA_MIN_VERSION: u8 = 11; /// The version new files are initially created with. pub(super) const SCHEMA_STARTING_VERSION: u8 = 11; /// The maximum schema version we can open. -pub(super) const SCHEMA_MAX_VERSION: u8 = 17; +pub(super) const SCHEMA_MAX_VERSION: u8 = 18; use super::SqliteStorage; use crate::err::Result; @@ -35,9 +35,14 @@ impl SqliteStorage { self.upgrade_tags_to_schema17()?; self.db.execute_batch("update col set ver = 17")?; } - // fixme: on the next schema upgrade, change _collapsed to _expanded - // in DeckCommon and invert existing values, so that we can avoid - // serializing the values in the default case, and use + if ver < 18 { + self.db + .execute_batch(include_str!("schema18_upgrade.sql"))?; + } + + // in some future schema upgrade, we may want to change + // _collapsed to _expanded in DeckCommon and invert existing values, so + // that we can avoid serializing the values in the default case, and use // DeckCommon::default() in new_normal() and new_filtered() Ok(()) @@ -46,6 +51,8 @@ impl SqliteStorage { pub(super) fn downgrade_to_schema_11(&self) -> Result<()> { self.begin_trx()?; + self.db + .execute_batch(include_str!("schema18_downgrade.sql"))?; self.downgrade_deck_conf_from_schema16()?; self.downgrade_decks_from_schema15()?; self.downgrade_notetypes_from_schema15()?; diff --git a/rslib/src/storage/upgrades/schema18_downgrade.sql b/rslib/src/storage/upgrades/schema18_downgrade.sql new file mode 100644 index 000000000..bd0eaa88e --- /dev/null +++ b/rslib/src/storage/upgrades/schema18_downgrade.sql @@ -0,0 +1,15 @@ +ALTER TABLE graves + RENAME TO graves_old; +CREATE TABLE graves ( + usn integer NOT NULL, + oid integer NOT NULL, + type integer NOT NULL +); +INSERT INTO graves (usn, oid, type) +SELECT usn, + oid, + type +FROM graves_old; +DROP TABLE graves_old; +UPDATE col +SET ver = 17; \ No newline at end of file diff --git a/rslib/src/storage/upgrades/schema18_upgrade.sql b/rslib/src/storage/upgrades/schema18_upgrade.sql new file mode 100644 index 000000000..600676f46 --- /dev/null +++ b/rslib/src/storage/upgrades/schema18_upgrade.sql @@ -0,0 +1,18 @@ +ALTER TABLE graves + RENAME TO graves_old; +CREATE TABLE graves ( + oid integer NOT NULL, + type integer NOT NULL, + usn integer NOT NULL, + PRIMARY KEY (oid, type) +) WITHOUT ROWID; +INSERT + OR IGNORE INTO graves (oid, type, usn) +SELECT oid, + type, + usn +FROM graves_old; +DROP TABLE graves_old; +CREATE INDEX idx_graves_pending ON graves (usn); +UPDATE col +SET ver = 18; \ No newline at end of file