use serde::{Deserialize, Serialize};
use std::collections::HashMap;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TableSnapshot {
pub table_name: String,
pub columns: Vec<ColumnDefinition>,
pub constraints: Vec<ConstraintDefinition>,
}
impl TableSnapshot {
pub fn new(table_name: String) -> Self {
Self {
table_name,
columns: Vec::new(),
constraints: Vec::new(),
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ColumnDefinition {
pub name: String,
pub data_type: String,
pub nullable: bool,
pub default_value: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ConstraintDefinition {
pub name: Option<String>,
pub constraint_type: String,
pub columns: Vec<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MigrationMetadata {
pub version: u32,
pub name: String,
pub up_sql: String,
pub down_sql: Option<String>,
pub table_snapshots: HashMap<String, TableSnapshot>,
}
impl MigrationMetadata {
pub fn new(version: u32, name: String, up_sql: String) -> Self {
Self {
version,
name,
up_sql,
down_sql: None,
table_snapshots: HashMap::new(),
}
}
pub fn add_table_snapshot(&mut self, snapshot: TableSnapshot) {
self.table_snapshots.insert(snapshot.table_name.clone(), snapshot);
}
}