mirror of
https://github.com/launchbadge/sqlx.git
synced 2025-09-30 06:22:01 +00:00
Edit Migration and Migrator to make embedded migrations possible
This commit is contained in:
parent
eba6f3973d
commit
60c3ece671
@ -2,18 +2,8 @@ use std::borrow::Cow;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Migration {
|
||||
pub(crate) version: i64,
|
||||
pub(crate) description: Cow<'static, str>,
|
||||
pub(crate) sql: Cow<'static, str>,
|
||||
pub(crate) checksum: Cow<'static, [u8]>,
|
||||
}
|
||||
|
||||
impl Migration {
|
||||
pub fn version(&self) -> i64 {
|
||||
self.version
|
||||
}
|
||||
|
||||
pub fn description(&self) -> &str {
|
||||
&*self.description
|
||||
}
|
||||
pub version: i64,
|
||||
pub description: Cow<'static, str>,
|
||||
pub sql: Cow<'static, str>,
|
||||
pub checksum: Cow<'static, [u8]>,
|
||||
}
|
||||
|
@ -1,11 +1,12 @@
|
||||
use crate::acquire::Acquire;
|
||||
use crate::migrate::{Migrate, MigrateError, Migration, MigrationSource};
|
||||
use std::borrow::Cow;
|
||||
use std::ops::Deref;
|
||||
use std::slice;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Migrator {
|
||||
migrations: Vec<Migration>,
|
||||
migrations: Cow<'static, [Migration]>,
|
||||
}
|
||||
|
||||
impl Migrator {
|
||||
@ -31,10 +32,17 @@ impl Migrator {
|
||||
S: MigrationSource<'s>,
|
||||
{
|
||||
Ok(Self {
|
||||
migrations: source.resolve().await.map_err(MigrateError::Source)?,
|
||||
migrations: Cow::Owned(source.resolve().await.map_err(MigrateError::Source)?),
|
||||
})
|
||||
}
|
||||
|
||||
/// Creates a new instance from a static slice of migrations.
|
||||
pub async fn from_static(migrations: &'static [Migration]) -> Self {
|
||||
Self {
|
||||
migrations: Cow::Borrowed(migrations),
|
||||
}
|
||||
}
|
||||
|
||||
/// Get an iterator over all known migrations.
|
||||
pub fn iter(&self) -> slice::Iter<'_, Migration> {
|
||||
self.migrations.iter()
|
||||
|
Loading…
x
Reference in New Issue
Block a user