risingwave_meta_model/
fragment_relation.rs

1// Copyright 2025 RisingWave Labs
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use sea_orm::entity::prelude::*;
16use serde::{Deserialize, Serialize};
17
18use crate::{DispatcherType, FragmentId, I32Array, TypePairArray};
19
20#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
21#[sea_orm(table_name = "fragment_relation")]
22pub struct Model {
23    #[sea_orm(primary_key)]
24    pub source_fragment_id: FragmentId,
25    #[sea_orm(primary_key)]
26    pub target_fragment_id: FragmentId,
27    pub dispatcher_type: DispatcherType,
28    pub dist_key_indices: I32Array,
29    pub output_indices: I32Array,
30    // `None` or empty array means no output type mapping.
31    pub output_type_mapping: Option<TypePairArray>,
32}
33
34#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
35pub enum Relation {
36    #[sea_orm(
37        belongs_to = "super::fragment::Entity",
38        from = "Column::SourceFragmentId",
39        to = "super::fragment::Column::FragmentId",
40        on_update = "NoAction",
41        on_delete = "Cascade"
42    )]
43    SourceFragment,
44    #[sea_orm(
45        belongs_to = "super::fragment::Entity",
46        from = "Column::TargetFragmentId",
47        to = "super::fragment::Column::FragmentId",
48        on_update = "NoAction",
49        on_delete = "Cascade"
50    )]
51    TargetFragment,
52}
53
54impl ActiveModelBehavior for ActiveModel {}