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