use crate::constraints::{Constraint, OrderBy};
#[derive(Debug, Clone)]
pub struct TableSchema {
pub table_name: String,
pub columns: Vec<ColumnDef>,
pub constraints: Vec<Constraint>,
pub ordering: Vec<OrderBy>,
pub managed: bool,
pub comment: Option<String>,
}
impl Default for TableSchema {
fn default() -> Self {
Self {
table_name: String::new(),
columns: Vec::new(),
constraints: Vec::new(),
ordering: Vec::new(),
managed: true,
comment: None,
}
}
}
#[derive(Debug, Clone)]
pub struct ColumnDef {
pub name: String,
pub col_type: ColumnType,
pub nullable: bool,
pub primary_key: bool,
pub unique: bool,
pub default: Option<DefaultValue>,
pub references: Option<FkReference>,
pub index: bool,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ColumnType {
Bool,
SmallInt,
Int,
BigInt,
AutoInt,
AutoBigInt,
Float,
Double,
Decimal {
precision: u8,
scale: u8,
},
Text,
Varchar(u32),
Bytea,
Uuid,
Date,
Time,
DateTime,
Json,
Jsonb, }
#[derive(Debug, Clone)]
pub enum DefaultValue {
Literal(String),
CurrentTimestamp,
GeneratedUuid,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct FkReference {
pub table: String,
pub column: String,
pub on_delete: ReferentialAction,
pub on_update: ReferentialAction,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ReferentialAction {
Cascade,
SetNull,
SetDefault,
Restrict,
NoAction,
}