reifydb_core/interface/catalog/
migration.rs1use reifydb_runtime::hash::{Hash128, xxh3_128};
5use serde::{Deserialize, Serialize};
6
7use crate::interface::catalog::id::{MigrationEventId, MigrationId};
8
9#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11pub struct Migration {
12 pub id: MigrationId,
13 pub name: String,
14 pub body: String,
16 pub rollback_body: Option<String>,
18 pub hash: Hash128,
22}
23
24pub fn migration_hash(body: &str, rollback_body: Option<&str>) -> Hash128 {
30 let mut buf = Vec::with_capacity(body.len() + 1 + rollback_body.map(|r| r.len()).unwrap_or(0));
31 buf.extend_from_slice(body.as_bytes());
32 buf.push(0);
33 if let Some(rb) = rollback_body {
34 buf.extend_from_slice(rb.as_bytes());
35 }
36 xxh3_128(&buf)
37}
38
39#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
42pub struct MigrationEvent {
43 pub id: MigrationEventId,
44 pub migration_id: MigrationId,
45 pub action: MigrationAction,
46}
47
48#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
50pub enum MigrationAction {
51 Applied,
52 Rollback,
53}