Going somewhere.

This commit is contained in:
didier amyot committed 2022-12-08 11:07:35 -05:00
1 parent 4a86c4250a
commit 511b2a88f6
6 files changed
+127 -18

No files matched your search

+15 -3
View File
@@ -1,6 +1,7 @@
use std::time::Instant;
use rusqlite::{Connection, Transaction};
use sha2::{Digest, Sha256};
use resource::{resource_str};
#[derive(Debug)]
pub enum IntegrityError {
@@ -52,13 +53,12 @@ pub fn migrate(conn: &mut Connection, migrations: &Vec<String>) -> Result<(), Er
fn apply_migration(tx: &Transaction, id: usize, migration: &String) -> Result<(), Error> {
let hash = compute_migration_sha256(migration);
let q = "INSERT INTO shitty_migrations(id, sha256) VALUES (?1, ?2)";
tx.execute(q, (&id, &hash)).map_err(|e| Error::Sql(e))?;
// let migration_id = tx.last_insert_rowid();
let now = Instant::now();
tx.execute(migration, ()).map_err(|e| Error::Sql(e))?;
tx.execute_batch(migration).map_err(|e| Error::Sql(e))?;
let elapsed_time = now.elapsed();
let q = "UPDATE shitty_migrations SET duration = ?1 WHERE id = ?2";
@@ -89,6 +89,18 @@ fn check_migration(tx: &Transaction, id: usize, migration: &String) -> Result<()
return Ok(());
}
fn get_migrations() -> Vec<String> {
let mut ret = Vec::new();
ret.push(resource_str!("migrations/create_tables_001.sql").as_ref().to_string());
return ret;
}
pub fn apply_migrations(conn: &mut Connection) -> Result<(), Error> {
let migrations = get_migrations();
return migrate(conn, &migrations);
}
#[cfg(test)]
mod test {
use super::*;