(self)
| 429 | // Private functions. Do not expose. |
| 430 | |
| 431 | fn migrate(self) -> Result<Self, DatabaseError> { |
| 432 | let mut conn = self.pool.get()?; |
| 433 | let transaction = conn.transaction()?; |
| 434 | |
| 435 | let max_version = max_migration_version(&transaction); |
| 436 | |
| 437 | for (version, migration) in MIGRATIONS.iter().enumerate() { |
| 438 | if has_migration(&transaction, version, max_version)? { |
| 439 | continue; |
| 440 | } |
| 441 | |
| 442 | // execute the migration |
| 443 | transaction.execute_batch(migration.sql)?; |
| 444 | |
| 445 | info!(%version, name =% migration.name, "Applying migration"); |
| 446 | |
| 447 | // insert the migration entry |
| 448 | transaction.execute( |
| 449 | "INSERT INTO migrations (version, migration_time) VALUES (?1, strftime('%s', 'now'));", |
| 450 | params![version], |
| 451 | )?; |
| 452 | } |
| 453 | |
| 454 | // commit the transaction |
| 455 | transaction.commit()?; |
| 456 | |
| 457 | Ok(self) |
| 458 | } |
| 459 | |
| 460 | fn get_entry<T: FromSql>(&self, table: Table, key: impl AsRef<str>) -> Result<Option<T>, DatabaseError> { |
| 461 | let conn = self.pool.get()?; |
no test coverage detected