risingwave_meta_model/
fragment.rsuse risingwave_pb::meta::table_fragments::fragment::PbFragmentDistributionType;
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
use crate::{FragmentId, I32Array, ObjectId, StreamNode};
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
#[sea_orm(table_name = "fragment")]
pub struct Model {
#[sea_orm(primary_key)]
pub fragment_id: FragmentId,
pub job_id: ObjectId,
pub fragment_type_mask: i32,
pub distribution_type: DistributionType,
pub stream_node: StreamNode,
pub state_table_ids: I32Array,
pub upstream_fragment_id: I32Array,
pub vnode_count: i32,
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, EnumIter, DeriveActiveEnum, Serialize, Deserialize)]
#[sea_orm(rs_type = "String", db_type = "string(None)")]
pub enum DistributionType {
#[sea_orm(string_value = "SINGLE")]
Single,
#[sea_orm(string_value = "HASH")]
Hash,
}
impl From<DistributionType> for PbFragmentDistributionType {
fn from(val: DistributionType) -> Self {
match val {
DistributionType::Single => PbFragmentDistributionType::Single,
DistributionType::Hash => PbFragmentDistributionType::Hash,
}
}
}
impl From<PbFragmentDistributionType> for DistributionType {
fn from(val: PbFragmentDistributionType) -> Self {
match val {
PbFragmentDistributionType::Unspecified => unreachable!(),
PbFragmentDistributionType::Single => DistributionType::Single,
PbFragmentDistributionType::Hash => DistributionType::Hash,
}
}
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(has_many = "super::actor::Entity")]
Actor,
#[sea_orm(has_many = "super::actor_dispatcher::Entity")]
ActorDispatcher,
#[sea_orm(
belongs_to = "super::object::Entity",
from = "Column::JobId",
to = "super::object::Column::Oid",
on_update = "NoAction",
on_delete = "Cascade"
)]
Object,
}
impl Related<super::actor::Entity> for Entity {
fn to() -> RelationDef {
Relation::Actor.def()
}
}
impl Related<super::actor_dispatcher::Entity> for Entity {
fn to() -> RelationDef {
Relation::ActorDispatcher.def()
}
}
impl Related<super::object::Entity> for Entity {
fn to() -> RelationDef {
Relation::Object.def()
}
}
impl ActiveModelBehavior for ActiveModel {}