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)]
10pub struct Migration {
11 pub id: MigrationId,
12 pub name: String,
13
14 pub body: String,
15
16 pub rollback_body: Option<String>,
17
18 pub hash: Hash128,
19}
20
21pub fn migration_hash(body: &str, rollback_body: Option<&str>) -> Hash128 {
22 let mut buf = Vec::with_capacity(body.len() + 1 + rollback_body.map(|r| r.len()).unwrap_or(0));
23 buf.extend_from_slice(body.as_bytes());
24 buf.push(0);
25 if let Some(rb) = rollback_body {
26 buf.extend_from_slice(rb.as_bytes());
27 }
28 xxh3_128(&buf)
29}
30
31#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
32pub struct MigrationEvent {
33 pub id: MigrationEventId,
34 pub migration_id: MigrationId,
35 pub action: MigrationAction,
36}
37
38#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
39pub enum MigrationAction {
40 Applied,
41 Rollback,
42}