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
#[cfg(feature = "with-serde")]
use serde::{Deserialize, Serialize};
use crate as sea_schema;
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "with-serde", derive(Serialize, Deserialize))]
pub enum Constraint {
Check(Check),
NotNull(NotNull),
Unique(Unique),
PrimaryKey(PrimaryKey),
References(References),
Exclusion(Exclusion),
}
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "with-serde", derive(Serialize, Deserialize))]
pub struct Check {
pub name: String,
pub expr: String,
pub no_inherit: bool,
}
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "with-serde", derive(Serialize, Deserialize))]
pub struct NotNull;
impl NotNull {
pub fn from_bool(boolean: bool) -> Option<NotNull> {
if boolean {
Some(NotNull)
} else {
None
}
}
}
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "with-serde", derive(Serialize, Deserialize))]
pub struct Unique {
pub name: String,
pub columns: Vec<String>,
}
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "with-serde", derive(Serialize, Deserialize))]
pub struct PrimaryKey {
pub name: String,
pub columns: Vec<String>,
}
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "with-serde", derive(Serialize, Deserialize))]
pub struct References {
pub name: String,
pub columns: Vec<String>,
pub table: String,
pub foreign_columns: Vec<String>,
pub on_update: Option<ForeignKeyAction>,
pub on_delete: Option<ForeignKeyAction>,
}
#[derive(Clone, Debug, PartialEq, sea_schema_derive::Name)]
#[cfg_attr(feature = "with-serde", derive(Serialize, Deserialize))]
pub enum ForeignKeyAction {
#[name = "CASCADE"]
Cascade,
#[name = "SET NULL"]
SetNull,
#[name = "SET DEFAULT"]
SetDefault,
#[name = "RESTRICT"]
Restrict,
#[name = "NO ACTION"]
NoAction,
}
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "with-serde", derive(Serialize, Deserialize))]
pub struct Exclusion {
pub name: String,
pub using: String,
pub columns: Vec<String>,
pub operation: String,
}