use std::collections::HashSet;
use serde::{Deserialize, Serialize};
use crate::operations::Operation;
use crate::states::types::EntityKind;
fn bool_true() -> bool {
true
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Migration {
#[serde(skip)]
pub id: String,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub dependencies: Vec<String>,
pub operations: Vec<Operation>,
#[serde(default = "bool_true", skip_serializing_if = "std::ops::Not::not")]
pub atomic: bool,
}
impl Migration {
pub fn from_yaml_str(s: &str) -> Result<Self, serde_yaml::Error> {
serde_yaml::from_str(s)
}
pub fn to_yaml_string(&self) -> Result<String, serde_yaml::Error> {
serde_yaml::to_string(self)
}
pub fn get_entities(&self) -> HashSet<(EntityKind, String)> {
self.operations
.iter()
.flat_map(Operation::touched_entities)
.collect()
}
}