risingwave_meta_model_migration/
m20250702_062029_cdc_table_snapshot_splits.rs1use sea_orm_migration::prelude::*;
2
3use crate::m20230908_072257_init::Object;
4use crate::utils::ColumnDefExt;
5
6#[derive(DeriveMigrationName)]
7pub struct Migration;
8
9#[async_trait::async_trait]
10impl MigrationTrait for Migration {
11 async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
12 manager
13 .create_table(
14 Table::create()
15 .table(CdcTableSnapshotSplits::Table)
16 .if_not_exists()
17 .col(
18 ColumnDef::new(CdcTableSnapshotSplits::TableId)
19 .integer()
20 .not_null(),
21 )
22 .col(
23 ColumnDef::new(CdcTableSnapshotSplits::SplitId)
24 .big_integer()
25 .not_null(),
26 )
27 .col(
28 ColumnDef::new(CdcTableSnapshotSplits::Left)
29 .rw_binary(manager)
30 .not_null(),
31 )
32 .col(
33 ColumnDef::new(CdcTableSnapshotSplits::Right)
34 .rw_binary(manager)
35 .not_null(),
36 )
37 .primary_key(
38 Index::create()
39 .col(CdcTableSnapshotSplits::TableId)
40 .col(CdcTableSnapshotSplits::SplitId),
41 )
42 .foreign_key(
43 &mut ForeignKey::create()
44 .name("FK_cdc_table_snapshot_splits_table_id")
45 .from(
46 CdcTableSnapshotSplits::Table,
47 CdcTableSnapshotSplits::TableId,
48 )
49 .to(Object::Table, Object::Oid)
50 .on_delete(ForeignKeyAction::Cascade)
51 .to_owned(),
52 )
53 .to_owned(),
54 )
55 .await
56 }
57
58 async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
59 manager
60 .drop_table(
61 Table::drop()
62 .table(CdcTableSnapshotSplits::Table)
63 .to_owned(),
64 )
65 .await
66 }
67}
68
69#[derive(DeriveIden)]
70enum CdcTableSnapshotSplits {
71 Table,
72 TableId,
73 SplitId,
74 Left,
75 Right,
76}