mirror of
https://github.com/launchbadge/sqlx.git
synced 2025-10-02 15:25:32 +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)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Migration {
|
pub struct Migration {
|
||||||
pub(crate) version: i64,
|
pub version: i64,
|
||||||
pub(crate) description: Cow<'static, str>,
|
pub description: Cow<'static, str>,
|
||||||
pub(crate) sql: Cow<'static, str>,
|
pub sql: Cow<'static, str>,
|
||||||
pub(crate) checksum: Cow<'static, [u8]>,
|
pub checksum: Cow<'static, [u8]>,
|
||||||
}
|
|
||||||
|
|
||||||
impl Migration {
|
|
||||||
pub fn version(&self) -> i64 {
|
|
||||||
self.version
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn description(&self) -> &str {
|
|
||||||
&*self.description
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
use crate::acquire::Acquire;
|
use crate::acquire::Acquire;
|
||||||
use crate::migrate::{Migrate, MigrateError, Migration, MigrationSource};
|
use crate::migrate::{Migrate, MigrateError, Migration, MigrationSource};
|
||||||
|
use std::borrow::Cow;
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
use std::slice;
|
use std::slice;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Migrator {
|
pub struct Migrator {
|
||||||
migrations: Vec<Migration>,
|
migrations: Cow<'static, [Migration]>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Migrator {
|
impl Migrator {
|
||||||
@ -31,10 +32,17 @@ impl Migrator {
|
|||||||
S: MigrationSource<'s>,
|
S: MigrationSource<'s>,
|
||||||
{
|
{
|
||||||
Ok(Self {
|
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.
|
/// Get an iterator over all known migrations.
|
||||||
pub fn iter(&self) -> slice::Iter<'_, Migration> {
|
pub fn iter(&self) -> slice::Iter<'_, Migration> {
|
||||||
self.migrations.iter()
|
self.migrations.iter()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user