risingwave_meta_model_migration/
m20241202_071413_resource_group.rs

1use sea_orm_migration::prelude::*;
2
3#[derive(DeriveMigrationName)]
4pub struct Migration;
5
6pub const DEFAULT_RESOURCE_GROUP: &str = "default";
7
8#[async_trait::async_trait]
9impl MigrationTrait for Migration {
10    async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
11        // drop old node_label column
12        manager
13            .alter_table(
14                Table::alter()
15                    .table(WorkerProperty::Table)
16                    .drop_column(WorkerProperty::Label)
17                    .to_owned(),
18            )
19            .await?;
20
21        manager
22            .alter_table(
23                Table::alter()
24                    .table(WorkerProperty::Table)
25                    .add_column(ColumnDef::new(WorkerProperty::ResourceGroup).string())
26                    .to_owned(),
27            )
28            .await?;
29
30        manager
31            .alter_table(
32                Table::alter()
33                    .table(StreamingJob::Table)
34                    .add_column(ColumnDef::new(StreamingJob::SpecificResourceGroup).string())
35                    .to_owned(),
36            )
37            .await?;
38
39        manager
40            .alter_table(
41                Table::alter()
42                    .table(Database::Table)
43                    .add_column(
44                        ColumnDef::new(Database::ResourceGroup)
45                            .string()
46                            .default(DEFAULT_RESOURCE_GROUP.to_string())
47                            .not_null(),
48                    )
49                    .to_owned(),
50            )
51            .await
52    }
53
54    async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
55        // restore old node_label column
56        manager
57            .alter_table(
58                Table::alter()
59                    .table(WorkerProperty::Table)
60                    .add_column(ColumnDef::new(WorkerProperty::Label).string())
61                    .to_owned(),
62            )
63            .await?;
64
65        manager
66            .alter_table(
67                Table::alter()
68                    .table(WorkerProperty::Table)
69                    .drop_column(WorkerProperty::ResourceGroup)
70                    .to_owned(),
71            )
72            .await?;
73        manager
74            .alter_table(
75                Table::alter()
76                    .table(StreamingJob::Table)
77                    .drop_column(StreamingJob::SpecificResourceGroup)
78                    .to_owned(),
79            )
80            .await?;
81        manager
82            .alter_table(
83                Table::alter()
84                    .table(Database::Table)
85                    .drop_column(Database::ResourceGroup)
86                    .to_owned(),
87            )
88            .await
89    }
90}
91
92#[derive(DeriveIden)]
93enum WorkerProperty {
94    Table,
95    ResourceGroup,
96    Label,
97}
98
99#[derive(DeriveIden)]
100enum StreamingJob {
101    Table,
102    SpecificResourceGroup,
103}
104
105#[derive(DeriveIden)]
106enum Database {
107    Table,
108    ResourceGroup,
109}