sqlx_core_oldapi/migrate/
migration.rs

1use std::borrow::Cow;
2
3use sha2::{Digest, Sha384};
4
5use super::MigrationType;
6
7#[derive(Debug, Clone)]
8pub struct Migration {
9    pub version: i64,
10    pub description: Cow<'static, str>,
11    pub migration_type: MigrationType,
12    pub sql: Cow<'static, str>,
13    pub checksum: Cow<'static, [u8]>,
14}
15
16impl std::fmt::Display for Migration {
17    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
18        write!(f, "Migration {} ({})", self.version, self.description)
19    }
20}
21
22impl Migration {
23    pub fn new(
24        version: i64,
25        description: Cow<'static, str>,
26        migration_type: MigrationType,
27        sql: Cow<'static, str>,
28    ) -> Self {
29        let checksum = Cow::Owned(Vec::from(Sha384::digest(sql.as_bytes()).as_slice()));
30
31        Migration {
32            version,
33            description,
34            migration_type,
35            sql,
36            checksum,
37        }
38    }
39}
40
41#[derive(Debug, Clone)]
42pub struct AppliedMigration {
43    pub version: i64,
44    pub checksum: Cow<'static, [u8]>,
45}