risingwave_meta_model/
pending_sink_state.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::{Epoch, SinkId};
19
20#[derive(Clone, Debug, PartialEq, Eq, EnumIter, DeriveActiveEnum, Serialize, Deserialize)]
21#[sea_orm(rs_type = "String", db_type = "string(None)")]
22pub enum SinkState {
23    #[sea_orm(string_value = "PENDING")]
24    Pending,
25    #[sea_orm(string_value = "COMMITTED")]
26    Committed,
27    #[sea_orm(string_value = "ABORTED")]
28    Aborted,
29}
30
31#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
32#[sea_orm(table_name = "pending_sink_state")]
33pub struct Model {
34    #[sea_orm(primary_key, auto_increment = false)]
35    pub sink_id: SinkId,
36    #[sea_orm(primary_key, auto_increment = false)]
37    pub epoch: Epoch,
38    pub sink_state: SinkState,
39    pub metadata: Vec<u8>,
40}
41
42impl ActiveModelBehavior for ActiveModel {}
43
44#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
45pub enum Relation {
46    #[sea_orm(
47        belongs_to = "super::sink::Entity",
48        from = "Column::SinkId",
49        to = "super::sink::Column::SinkId",
50        on_update = "NoAction",
51        on_delete = "Cascade"
52    )]
53    Sink,
54    #[sea_orm(
55        belongs_to = "super::object::Entity",
56        from = "Column::SinkId",
57        to = "super::object::Column::Oid",
58        on_update = "NoAction",
59        on_delete = "Cascade"
60    )]
61    Object,
62}