risingwave_meta_model_migration/
m20240911_083152_variable_vnode_count.rs

1use sea_orm_migration::prelude::{Table as MigrationTable, *};
2
3macro_rules! col {
4    ($name:expr) => {
5        ColumnDef::new($name).integer().not_null().default(256) // compat vnode count
6    };
7}
8
9#[derive(DeriveMigrationName)]
10pub struct Migration;
11
12#[async_trait::async_trait]
13impl MigrationTrait for Migration {
14    async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
15        manager
16            .alter_table(
17                MigrationTable::alter()
18                    .table(Table::Table)
19                    .add_column(col!(Table::VnodeCount))
20                    .to_owned(),
21            )
22            .await?;
23
24        manager
25            .alter_table(
26                MigrationTable::alter()
27                    .table(Fragment::Table)
28                    .add_column(col!(Fragment::VnodeCount))
29                    .to_owned(),
30            )
31            .await?;
32
33        manager
34            .alter_table(
35                MigrationTable::alter()
36                    .table(StreamingJob::Table)
37                    .add_column(col!(StreamingJob::MaxParallelism))
38                    .to_owned(),
39            )
40            .await
41    }
42
43    async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
44        manager
45            .alter_table(
46                MigrationTable::alter()
47                    .table(Table::Table)
48                    .drop_column(Table::VnodeCount)
49                    .to_owned(),
50            )
51            .await?;
52
53        manager
54            .alter_table(
55                MigrationTable::alter()
56                    .table(Fragment::Table)
57                    .drop_column(Fragment::VnodeCount)
58                    .to_owned(),
59            )
60            .await?;
61
62        manager
63            .alter_table(
64                MigrationTable::alter()
65                    .table(StreamingJob::Table)
66                    .drop_column(StreamingJob::MaxParallelism)
67                    .to_owned(),
68            )
69            .await
70    }
71}
72
73#[derive(DeriveIden)]
74enum Fragment {
75    Table,
76    VnodeCount,
77}
78
79#[derive(DeriveIden)]
80enum Table {
81    Table,
82    VnodeCount,
83}
84
85#[derive(DeriveIden)]
86enum StreamingJob {
87    Table,
88    MaxParallelism,
89}