Skip to main content

schema_diff/
change.rs

1use schema_model::model::column::Column;
2use schema_model::model::constraint::Constraint;
3use schema_model::model::enum_type::EnumType;
4use schema_model::model::function::Function;
5use schema_model::model::initial_data::InitialData;
6use schema_model::model::key::Key;
7use schema_model::model::other_sql::OtherSql;
8use schema_model::model::procedure::Procedure;
9use schema_model::model::relation::Relation;
10use schema_model::model::table::Table;
11use schema_model::model::trigger::Trigger;
12use schema_model::model::types::DatabaseType;
13use schema_model::model::view::View;
14
15#[derive(Debug, Clone)]
16pub enum SchemaChange {
17    AddTable {
18        table: Table,
19    },
20    DropTable {
21        table_name: String,
22    },
23    AddColumn {
24        table_name: String,
25        column: Column,
26    },
27    DropColumn {
28        table_name: String,
29        column_name: String,
30        rename_candidates: Vec<String>,
31    },
32    ModifyColumn {
33        table_name: String,
34        old_column: Column,
35        new_column: Column,
36    },
37    AddKey {
38        table_name: String,
39        key: Key,
40        /// 1-based position of `key` among the sibling keys the create path numbers it
41        /// with - unique keys are numbered among the table's other unique keys, indexes
42        /// among the table's other indexes - so a migration can reproduce the exact
43        /// `ak_<table><n>` / `ix_<table><n>` name the create path would use.
44        ordinal: usize,
45    },
46    DropKey {
47        table_name: String,
48        key: Key,
49        /// See `AddKey::ordinal`.
50        ordinal: usize,
51    },
52    AddConstraint {
53        table_name: String,
54        constraint: Constraint,
55    },
56    DropConstraint {
57        table_name: String,
58        constraint_name: String,
59        database_type: DatabaseType,
60    },
61    AddRelation {
62        relation: Relation,
63        /// 1-based position of `relation` among its table's relations, matching the
64        /// create path's `fk_<table><n>` numbering.
65        ordinal: usize,
66    },
67    DropRelation {
68        relation: Relation,
69        /// See `AddRelation::ordinal`.
70        ordinal: usize,
71    },
72    AddView {
73        view: View,
74    },
75    DropView {
76        view_name: String,
77        database_type: Option<DatabaseType>,
78    },
79    AddEnumType {
80        enum_type: EnumType,
81    },
82    DropEnumType {
83        enum_type_name: String,
84    },
85    ModifyEnumType {
86        old_enum_type: EnumType,
87        new_enum_type: EnumType,
88    },
89    AddFunction {
90        function: Function,
91    },
92    DropFunction {
93        function_name: String,
94        database_type: DatabaseType,
95    },
96    AddProcedure {
97        procedure: Procedure,
98    },
99    DropProcedure {
100        procedure_name: String,
101        database_type: DatabaseType,
102    },
103    AddOtherSql {
104        other_sql: OtherSql,
105    },
106    DropOtherSql {
107        other_sql: OtherSql,
108    },
109    AddTrigger {
110        table_name: String,
111        trigger: Trigger,
112    },
113    DropTrigger {
114        table_name: String,
115        trigger: Trigger,
116    },
117    AddInitialData {
118        table_name: String,
119        initial_data: InitialData,
120    },
121    DropInitialData {
122        table_name: String,
123        initial_data: InitialData,
124    },
125}