mirror of
https://github.com/launchbadge/sqlx
synced 2024-11-10 14:34:19 +00:00
Allow MigrationSource to be implemented externally (#511)
This commit is contained in:
parent
05ffcb312d
commit
e0ace861c5
2 changed files with 19 additions and 8 deletions
|
@ -1,5 +1,7 @@
|
|||
use std::borrow::Cow;
|
||||
|
||||
use sha2::{Digest, Sha384};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Migration {
|
||||
pub version: i64,
|
||||
|
@ -7,3 +9,16 @@ pub struct Migration {
|
|||
pub sql: Cow<'static, str>,
|
||||
pub checksum: Cow<'static, [u8]>,
|
||||
}
|
||||
|
||||
impl Migration {
|
||||
pub fn new(version: i64, description: Cow<'static, str>, sql: Cow<'static, str>) -> Self {
|
||||
let checksum = Cow::Owned(Vec::from(Sha384::digest(sql.as_bytes()).as_slice()));
|
||||
|
||||
Migration {
|
||||
version,
|
||||
description,
|
||||
sql,
|
||||
checksum,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ use crate::error::BoxDynError;
|
|||
use crate::migrate::Migration;
|
||||
use futures_core::future::BoxFuture;
|
||||
use futures_util::TryStreamExt;
|
||||
use sha2::{Digest, Sha384};
|
||||
use sqlx_rt::fs;
|
||||
use std::borrow::Cow;
|
||||
use std::fmt::Debug;
|
||||
|
@ -44,14 +43,11 @@ impl<'s> MigrationSource<'s> for &'s Path {
|
|||
|
||||
let sql = fs::read_to_string(&entry.path()).await?;
|
||||
|
||||
let checksum = Vec::from(Sha384::digest(sql.as_bytes()).as_slice());
|
||||
|
||||
migrations.push(Migration {
|
||||
migrations.push(Migration::new(
|
||||
version,
|
||||
description: Cow::Owned(description),
|
||||
sql: Cow::Owned(sql),
|
||||
checksum: Cow::Owned(checksum),
|
||||
})
|
||||
Cow::Owned(description),
|
||||
Cow::Owned(sql),
|
||||
));
|
||||
}
|
||||
|
||||
// ensure that we are sorted by `VERSION ASC`
|
||||
|
|
Loading…
Reference in a new issue