risingwave_meta_model_migration/
m20240418_142249_function_runtime.rs

1use sea_orm_migration::prelude::{Table as MigrationTable, *};
2
3#[derive(DeriveMigrationName)]
4pub struct Migration;
5
6#[async_trait::async_trait]
7impl MigrationTrait for Migration {
8    async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
9        assert!(manager.has_table(Function::Table.to_string()).await?);
10
11        manager
12            .alter_table(
13                MigrationTable::alter()
14                    .table(Function::Table)
15                    .add_column(ColumnDef::new(Function::Runtime).string())
16                    .to_owned(),
17            )
18            .await?;
19
20        manager
21            .alter_table(
22                MigrationTable::alter()
23                    .table(Function::Table)
24                    .add_column(ColumnDef::new(Function::FunctionType).string())
25                    .to_owned(),
26            )
27            .await?;
28
29        Ok(())
30    }
31
32    async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
33        // drop tables cascade.
34
35        manager
36            .alter_table(
37                MigrationTable::alter()
38                    .table(Function::Table)
39                    .drop_column(Alias::new(Function::Runtime.to_string()))
40                    .to_owned(),
41            )
42            .await?;
43
44        manager
45            .alter_table(
46                MigrationTable::alter()
47                    .table(Function::Table)
48                    .drop_column(Alias::new(Function::FunctionType.to_string()))
49                    .to_owned(),
50            )
51            .await?;
52        Ok(())
53    }
54}
55
56#[derive(DeriveIden)]
57enum Function {
58    Table,
59    Runtime,
60    FunctionType,
61}