fix: bring back accidentally removed methods on the Migrate trait as deprecated

This commit is contained in:
Ryan Leckey
2021-05-21 17:16:22 -07:00
parent 012478d8b7
commit 2d38332137
5 changed files with 163 additions and 0 deletions

View File

@@ -107,6 +107,19 @@ CREATE TABLE IF NOT EXISTS _sqlx_migrations (
})
}
fn version(&mut self) -> BoxFuture<'_, Result<Option<(i64, bool)>, MigrateError>> {
Box::pin(async move {
// language=SQL
let row = query_as(
"SELECT version, NOT success FROM _sqlx_migrations ORDER BY version DESC LIMIT 1",
)
.fetch_optional(self)
.await?;
Ok(row)
})
}
fn dirty_version(&mut self) -> BoxFuture<'_, Result<Option<i64>, MigrateError>> {
Box::pin(async move {
// language=SQL
@@ -178,6 +191,30 @@ CREATE TABLE IF NOT EXISTS _sqlx_migrations (
})
}
fn validate<'e: 'm, 'm>(
&'e mut self,
migration: &'m Migration,
) -> BoxFuture<'m, Result<(), MigrateError>> {
Box::pin(async move {
// language=SQL
let checksum: Option<Vec<u8>> =
query_scalar("SELECT checksum FROM _sqlx_migrations WHERE version = $1")
.bind(migration.version)
.fetch_optional(self)
.await?;
if let Some(checksum) = checksum {
return if checksum == &*migration.checksum {
Ok(())
} else {
Err(MigrateError::VersionMismatch(migration.version))
};
} else {
Err(MigrateError::VersionMissing(migration.version))
}
})
}
fn apply<'e: 'm, 'm>(
&'e mut self,
migration: &'m Migration,