- match version {\r
- 0 => {\r
- println!("Update to version 1...");\r
- con.execute(\r
- "\r
- CREATE TABLE [Version] (\r
- [id] INTEGER PRIMARY KEY,\r
- [version] INTEGER NOT NULL,\r
- [datetime] INTEGER DATETIME\r
- )\r
- ",\r
- rusqlite::NO_PARAMS\r
- );\r
- con.execute(\r
- "\r
- CREATE TABLE [Recipe] (\r
- [id] INTEGER PRIMARY KEY,\r
- [title] INTEGER NOT NULL,\r
- [description] INTEGER DATETIME\r
- )\r
- ",\r
- rusqlite::NO_PARAMS\r
- );\r
- ()\r
+ while Connection::update_to_next_version(version, &tx)? {\r
+ version += 1;\r
+ }\r
+\r
+ tx.commit()?;\r
+\r
+ Ok(())\r
+ }\r
+\r
+ fn update_to_next_version(current_version: u32, tx: &rusqlite::Transaction) -> Result<bool, DBError> {\r
+ let next_version = current_version + 1;\r
+\r
+ if next_version <= CURRENT_DB_VERSION {\r
+ println!("Update to version {}...", next_version);\r
+ }\r
+\r
+ fn ok(updated: bool) -> Result<bool, DBError> {\r
+ if updated {\r
+ println!("Version updated");\r
+ }\r
+ Ok(updated)\r
+ }\r
+\r
+ match next_version {\r
+ 1 => {\r
+ tx.execute_batch(&load_sql_file(next_version)?)?;\r
+\r
+ ok(true)\r