risingwave_meta_model_migration/
m20240525_090457_secret.rs1use sea_orm_migration::prelude::{Table as MigrationTable, *};
2
3use crate::utils::ColumnDefExt;
4use crate::{assert_not_has_tables, drop_tables};
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 assert_not_has_tables!(manager, Secret);
13 manager
14 .create_table(
15 MigrationTable::create()
16 .table(Secret::Table)
17 .if_not_exists()
18 .col(
19 ColumnDef::new(Secret::SecretId)
20 .integer()
21 .not_null()
22 .primary_key(),
23 )
24 .col(ColumnDef::new(Secret::Name).string().not_null())
25 .col(ColumnDef::new(Secret::Value).rw_binary(manager).not_null())
26 .foreign_key(
27 &mut ForeignKey::create()
28 .name("FK_secret_object_id")
29 .from(Secret::Table, Secret::SecretId)
30 .to(
31 crate::m20230908_072257_init::Object::Table,
32 crate::m20230908_072257_init::Object::Oid,
33 )
34 .on_delete(ForeignKeyAction::Cascade)
35 .to_owned(),
36 )
37 .to_owned(),
38 )
39 .await?;
40
41 manager
43 .alter_table(
44 MigrationTable::alter()
45 .table(Sink::Table)
46 .add_column(ColumnDef::new(Sink::SecretRef).rw_binary(manager))
47 .to_owned(),
48 )
49 .await?;
50
51 manager
53 .alter_table(
54 MigrationTable::alter()
55 .table(Source::Table)
56 .add_column(ColumnDef::new(Source::SecretRef).rw_binary(manager))
57 .to_owned(),
58 )
59 .await?;
60
61 Ok(())
62 }
63
64 async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
65 drop_tables!(manager, Secret);
66 manager
67 .alter_table(
68 MigrationTable::alter()
69 .table(Sink::Table)
70 .drop_column(Sink::SecretRef)
71 .to_owned(),
72 )
73 .await?;
74 manager
75 .alter_table(
76 MigrationTable::alter()
77 .table(Source::Table)
78 .drop_column(Source::SecretRef)
79 .to_owned(),
80 )
81 .await?;
82 Ok(())
83 }
84}
85
86#[derive(DeriveIden)]
87enum Secret {
88 Table,
89 SecretId,
90 Name,
91 Value,
92}
93
94#[derive(DeriveIden)]
95enum Sink {
96 Table,
97 SecretRef,
98}
99
100#[derive(DeriveIden)]
101enum Source {
102 Table,
103 SecretRef,
104}