1use crate::constraints::{Constraint, OrderBy};
2
3#[derive(Debug, Clone)]
5pub struct TableSchema {
6 pub table_name: String,
7 pub columns: Vec<ColumnDef>,
8 pub constraints: Vec<Constraint>,
9 pub ordering: Vec<OrderBy>,
10 pub managed: bool,
11 pub comment: Option<String>,
12}
13
14impl Default for TableSchema {
15 fn default() -> Self {
16 Self {
17 table_name: String::new(),
18 columns: Vec::new(),
19 constraints: Vec::new(),
20 ordering: Vec::new(),
21 managed: true,
22 comment: None,
23 }
24 }
25}
26
27#[derive(Debug, Clone)]
29pub struct ColumnDef {
30 pub name: String,
31 pub col_type: ColumnType,
32 pub nullable: bool,
33 pub primary_key: bool,
34 pub unique: bool,
35 pub default: Option<DefaultValue>,
36 pub references: Option<FkReference>,
37 pub index: bool,
39}
40
41#[derive(Debug, Clone, PartialEq, Eq)]
44pub enum ColumnType {
45 Bool,
46 SmallInt,
47 Int,
48 BigInt,
49 AutoInt,
51 AutoBigInt,
53 Float,
54 Double,
55 Decimal {
56 precision: u8,
57 scale: u8,
58 },
59 Text,
60 Varchar(u32),
61 Bytea,
62 Uuid,
63 Date,
64 Time,
65 DateTime,
66 Json,
67 Jsonb, }
69
70#[derive(Debug, Clone)]
71pub enum DefaultValue {
72 Literal(String),
73 CurrentTimestamp,
74 GeneratedUuid,
75}
76
77#[derive(Debug, Clone, PartialEq, Eq)]
79pub struct FkReference {
80 pub table: String,
81 pub column: String,
82 pub on_delete: ReferentialAction,
83 pub on_update: ReferentialAction,
84}
85
86#[derive(Debug, Clone, PartialEq, Eq)]
88pub enum ReferentialAction {
89 Cascade,
90 SetNull,
91 SetDefault,
92 Restrict,
93 NoAction,
94}