(
&self,
migration: impl Send + FnOnce(&mut rusqlite::Transaction) -> Result<()>,
version: i32,
)
| 744 | } |
| 745 | |
| 746 | async fn execute_migration_transaction( |
| 747 | &self, |
| 748 | migration: impl Send + FnOnce(&mut rusqlite::Transaction) -> Result<()>, |
| 749 | version: i32, |
| 750 | ) -> Result<()> { |
| 751 | #[cfg(test)] |
| 752 | if STOP_MIGRATIONS_AT.try_with(|stop_migrations_at| version > *stop_migrations_at) |
| 753 | == Ok(true) |
| 754 | { |
| 755 | println!("Not running migration {version}, because STOP_MIGRATIONS_AT is set"); |
| 756 | return Ok(()); |
| 757 | } |
| 758 | |
| 759 | self.transaction(move |transaction| { |
| 760 | let curr_version: String = transaction.query_row( |
| 761 | "SELECT IFNULL(value, ?) FROM config WHERE keyname=?;", |
| 762 | ("0", VERSION_CFG), |
| 763 | |row| row.get(0), |
| 764 | )?; |
| 765 | let curr_version: i32 = curr_version.parse()?; |
| 766 | ensure!(curr_version < version, "Db version must be increased"); |
| 767 | Self::set_db_version_trans(transaction, version)?; |
| 768 | migration(transaction)?; |
| 769 | |
| 770 | Ok(()) |
| 771 | }) |
| 772 | .await |
| 773 | .with_context(|| format!("execute_migration failed for version {version}"))?; |
| 774 | |
| 775 | self.config_cache.write().await.clear(); |
| 776 | |
| 777 | Ok(()) |
| 778 | } |
| 779 | } |
| 780 | |
| 781 | #[expect(clippy::arithmetic_side_effects)] |
no test coverage detected