Skip to content

Commit

Permalink
add migration and entity files
Browse files Browse the repository at this point in the history
  • Loading branch information
connortsui20 committed Nov 27, 2024
1 parent 67b5ae8 commit d8c66d2
Show file tree
Hide file tree
Showing 14 changed files with 743 additions and 0 deletions.
76 changes: 76 additions & 0 deletions optd-mvp/src/entities/cascades_group.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0
use sea_orm::entity::prelude::*;

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
#[sea_orm(table_name = "cascades_group")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: i32,
pub winner: Option<i32>,
pub cost: Option<i64>,
pub is_optimized: bool,
pub parent_id: Option<i32>,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "Entity",
from = "Column::ParentId",
to = "Column::Id",
on_update = "Cascade",
on_delete = "SetNull"
)]
SelfRef,
#[sea_orm(has_many = "super::logical_children::Entity")]
LogicalChildren,
#[sea_orm(has_many = "super::logical_expression::Entity")]
LogicalExpression,
#[sea_orm(has_many = "super::physical_children::Entity")]
PhysicalChildren,
#[sea_orm(
belongs_to = "super::physical_expression::Entity",
from = "Column::Winner",
to = "super::physical_expression::Column::Id",
on_update = "Cascade",
on_delete = "SetNull"
)]
PhysicalExpression,
}

impl Related<super::logical_children::Entity> for Entity {
fn to() -> RelationDef {
Relation::LogicalChildren.def()
}
}

impl Related<super::physical_children::Entity> for Entity {
fn to() -> RelationDef {
Relation::PhysicalChildren.def()
}
}

impl Related<super::logical_expression::Entity> for Entity {
fn to() -> RelationDef {
super::logical_children::Relation::LogicalExpression.def()
}
fn via() -> Option<RelationDef> {
Some(super::logical_children::Relation::CascadesGroup.def().rev())
}
}

impl Related<super::physical_expression::Entity> for Entity {
fn to() -> RelationDef {
super::physical_children::Relation::PhysicalExpression.def()
}
fn via() -> Option<RelationDef> {
Some(
super::physical_children::Relation::CascadesGroup
.def()
.rev(),
)
}
}

impl ActiveModelBehavior for ActiveModel {}
46 changes: 46 additions & 0 deletions optd-mvp/src/entities/logical_children.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0
use sea_orm::entity::prelude::*;

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
#[sea_orm(table_name = "logical_children")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub logical_expression_id: i32,
#[sea_orm(primary_key, auto_increment = false)]
pub group_id: i32,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::cascades_group::Entity",
from = "Column::GroupId",
to = "super::cascades_group::Column::Id",
on_update = "Cascade",
on_delete = "Cascade"
)]
CascadesGroup,
#[sea_orm(
belongs_to = "super::logical_expression::Entity",
from = "Column::GroupId",
to = "super::logical_expression::Column::Id",
on_update = "Cascade",
on_delete = "Cascade"
)]
LogicalExpression,
}

impl Related<super::cascades_group::Entity> for Entity {
fn to() -> RelationDef {
Relation::CascadesGroup.def()
}
}

impl Related<super::logical_expression::Entity> for Entity {
fn to() -> RelationDef {
Relation::LogicalExpression.def()
}
}

impl ActiveModelBehavior for ActiveModel {}
49 changes: 49 additions & 0 deletions optd-mvp/src/entities/logical_expression.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0
use sea_orm::entity::prelude::*;

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
#[sea_orm(table_name = "logical_expression")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: i32,
pub group_id: i32,
pub fingerprint: i64,
pub kind: i16,
pub data: Json,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::cascades_group::Entity",
from = "Column::GroupId",
to = "super::cascades_group::Column::Id",
on_update = "Cascade",
on_delete = "Cascade"
)]
CascadesGroup,
#[sea_orm(has_many = "super::logical_children::Entity")]
LogicalChildren,
}

impl Related<super::logical_children::Entity> for Entity {
fn to() -> RelationDef {
Relation::LogicalChildren.def()
}
}

impl Related<super::cascades_group::Entity> for Entity {
fn to() -> RelationDef {
super::logical_children::Relation::CascadesGroup.def()
}
fn via() -> Option<RelationDef> {
Some(
super::logical_children::Relation::LogicalExpression
.def()
.rev(),
)
}
}

impl ActiveModelBehavior for ActiveModel {}
9 changes: 9 additions & 0 deletions optd-mvp/src/entities/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0
pub mod prelude;

pub mod cascades_group;
pub mod logical_children;
pub mod logical_expression;
pub mod physical_children;
pub mod physical_expression;
46 changes: 46 additions & 0 deletions optd-mvp/src/entities/physical_children.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0
use sea_orm::entity::prelude::*;

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
#[sea_orm(table_name = "physical_children")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub physical_expression_id: i32,
#[sea_orm(primary_key, auto_increment = false)]
pub group_id: i32,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::cascades_group::Entity",
from = "Column::GroupId",
to = "super::cascades_group::Column::Id",
on_update = "Cascade",
on_delete = "Cascade"
)]
CascadesGroup,
#[sea_orm(
belongs_to = "super::physical_expression::Entity",
from = "Column::PhysicalExpressionId",
to = "super::physical_expression::Column::Id",
on_update = "Cascade",
on_delete = "Cascade"
)]
PhysicalExpression,
}

impl Related<super::cascades_group::Entity> for Entity {
fn to() -> RelationDef {
Relation::CascadesGroup.def()
}
}

impl Related<super::physical_expression::Entity> for Entity {
fn to() -> RelationDef {
Relation::PhysicalExpression.def()
}
}

impl ActiveModelBehavior for ActiveModel {}
49 changes: 49 additions & 0 deletions optd-mvp/src/entities/physical_expression.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0
use sea_orm::entity::prelude::*;

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
#[sea_orm(table_name = "physical_expression")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: i32,
pub group_id: i32,
pub fingerprint: i64,
pub kind: i16,
pub data: Json,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::cascades_group::Entity",
from = "Column::GroupId",
to = "super::cascades_group::Column::Id",
on_update = "Cascade",
on_delete = "Cascade"
)]
CascadesGroup,
#[sea_orm(has_many = "super::physical_children::Entity")]
PhysicalChildren,
}

impl Related<super::physical_children::Entity> for Entity {
fn to() -> RelationDef {
Relation::PhysicalChildren.def()
}
}

impl Related<super::cascades_group::Entity> for Entity {
fn to() -> RelationDef {
super::physical_children::Relation::CascadesGroup.def()
}
fn via() -> Option<RelationDef> {
Some(
super::physical_children::Relation::PhysicalExpression
.def()
.rev(),
)
}
}

impl ActiveModelBehavior for ActiveModel {}
9 changes: 9 additions & 0 deletions optd-mvp/src/entities/prelude.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0
#![allow(unused_imports)]

pub use super::cascades_group::Entity as CascadesGroup;
pub use super::logical_children::Entity as LogicalChildren;
pub use super::logical_expression::Entity as LogicalExpression;
pub use super::physical_children::Entity as PhysicalChildren;
pub use super::physical_expression::Entity as PhysicalExpression;
Loading

0 comments on commit d8c66d2

Please sign in to comment.