use sea_query::ForeignKeyAction;
#[derive(Debug, Clone)]
pub struct ForeignKeyDef {
pub from_column: String,
pub to_table: String,
pub to_column: String,
pub on_delete: ForeignKeyAction,
pub on_update: ForeignKeyAction,
}
impl ForeignKeyDef {
pub fn new(from_column: impl Into<String>) -> Self {
Self {
from_column: from_column.into(),
to_table: String::new(),
to_column: "id".to_string(),
on_delete: ForeignKeyAction::NoAction,
on_update: ForeignKeyAction::NoAction,
}
}
pub fn references(mut self, table: impl Into<String>) -> Self {
self.to_table = table.into();
self
}
pub fn to_column(mut self, column: impl Into<String>) -> Self {
self.to_column = column.into();
self
}
pub fn on_delete(mut self, action: ForeignKeyAction) -> Self {
self.on_delete = action;
self
}
pub fn on_update(mut self, action: ForeignKeyAction) -> Self {
self.on_update = action;
self
}
}