1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
//! Atomic schema change representation — the output of model diffing.
use super::types::{
SnapshotCheck, SnapshotColumn, SnapshotForeignKey, SnapshotIndex, SnapshotTableOptions,
};
/// Single atomic schema change detected during diffing.
#[derive(Debug, Clone)]
pub(crate) enum SchemaChange {
CreateTable {
table: String,
columns: Vec<SnapshotColumn>,
checks: Vec<SnapshotCheck>,
table_options: SnapshotTableOptions,
/// Composite foreign keys. Single-column keys live on `columns`.
/// SQLite emits both inline (it cannot ALTER TABLE ADD CONSTRAINT).
foreign_keys: Vec<SnapshotForeignKey>,
/// Table comment.
comment: Option<String>,
},
DropTable {
table: String,
},
AddColumn {
table: String,
column: SnapshotColumn,
},
DropColumn {
table: String,
column_name: String,
},
AlterColumn {
table: String,
column_name: String,
old: Box<SnapshotColumn>,
new: Box<SnapshotColumn>,
},
AddForeignKey {
table: String,
column: String,
referenced_table: String,
referenced_column: String,
on_delete: Option<String>,
},
DropForeignKey {
table: String,
column: String,
referenced_table: String,
},
CreateIndex {
table: String,
column: String,
is_unique: bool,
},
DropIndex {
table: String,
column: String,
is_unique: bool,
},
/// Create a declared index (composite / partial / expression).
CreateDeclaredIndex {
table: String,
index: SnapshotIndex,
},
/// Drop a declared index (definition retained so Down can recreate it).
DropDeclaredIndex {
table: String,
index: SnapshotIndex,
},
/// Add a composite foreign key.
AddCompositeForeignKey {
table: String,
foreign_key: SnapshotForeignKey,
},
/// Drop a composite foreign key (definition retained for Down).
DropCompositeForeignKey {
table: String,
foreign_key: SnapshotForeignKey,
},
/// Add a table-level CHECK constraint.
AddCheck {
table: String,
check: SnapshotCheck,
},
/// Drop a table-level CHECK constraint (definition retained for Down).
DropCheck {
table: String,
check: SnapshotCheck,
},
/// Change MySQL table options (`ENGINE` / `CHARSET` / `COLLATE`).
AlterTableOptions {
table: String,
options: SnapshotTableOptions,
},
/// Change the table comment (old value retained for Down).
AlterTableComment {
table: String,
old_comment: Option<String>,
new_comment: Option<String>,
},
}