Skip to main content

rust_ef/migration/
types.rs

1//! Snapshot and migration data types.
2
3/// Represents a single migration with up/down SQL scripts.
4#[derive(Debug, Clone)]
5pub struct Migration {
6    pub id: String,
7    pub description: String,
8    pub up_sql: String,
9    pub down_sql: String,
10}
11
12/// A snapshot of the entity model at a point in time.
13/// Corresponds to EFCore's `ModelSnapshot`.
14#[derive(Debug, Clone)]
15pub struct ModelSnapshot {
16    pub migration_id: String,
17    pub entity_types: Vec<SnapshotEntityType>,
18}
19
20/// Serialized form of EntityTypeMeta for snapshot storage.
21#[derive(Debug, Clone)]
22pub struct SnapshotEntityType {
23    pub type_name: String,
24    pub table_name: String,
25    pub columns: Vec<SnapshotColumn>,
26}
27
28/// Serialized form of PropertyMeta for snapshot storage.
29#[derive(Debug, Clone, PartialEq, Default)]
30pub struct SnapshotColumn {
31    pub field_name: String,
32    pub column_name: String,
33    pub type_name: String,
34    pub is_primary_key: bool,
35    pub is_required: bool,
36    pub is_foreign_key: bool,
37    pub max_length: Option<usize>,
38    pub is_auto_increment: bool,
39    /// Whether this column is backed by a database sequence (PostgreSQL).
40    pub is_sequence: bool,
41    /// The sequence name when `is_sequence` is true.
42    pub sequence_name: Option<String>,
43    /// Referenced table when `is_foreign_key` is true.
44    pub fk_referenced_table: Option<String>,
45    /// Referenced column when `is_foreign_key` is true.
46    pub fk_referenced_column: Option<String>,
47    /// Non-unique index on this column.
48    pub has_index: bool,
49    /// Unique constraint/index on this column.
50    pub is_unique: bool,
51    /// ON DELETE clause for the FK constraint (e.g. "CASCADE", "SET NULL").
52    /// `None` means no explicit clause (DB default applies).
53    pub fk_on_delete: Option<String>,
54}