risingwave_meta_model_migration/
m20240304_074901_subscription.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, Subscription);
13 manager
14 .create_table(
15 MigrationTable::create()
16 .table(Subscription::Table)
17 .col(
18 ColumnDef::new(Subscription::SubscriptionId)
19 .integer()
20 .primary_key(),
21 )
22 .col(ColumnDef::new(Subscription::Name).string().not_null())
23 .col(
24 ColumnDef::new(Subscription::Columns)
25 .rw_binary(manager)
26 .not_null(),
27 )
28 .col(
29 ColumnDef::new(Subscription::PlanPk)
30 .rw_binary(manager)
31 .not_null(),
32 )
33 .col(
34 ColumnDef::new(Subscription::DistributionKey)
35 .json_binary()
36 .not_null(),
37 )
38 .col(
39 ColumnDef::new(Subscription::Properties)
40 .json_binary()
41 .not_null(),
42 )
43 .col(
44 ColumnDef::new(Subscription::Definition)
45 .rw_long_text(manager)
46 .not_null(),
47 )
48 .col(
49 ColumnDef::new(Subscription::SubscriptionFromName)
50 .string()
51 .not_null(),
52 )
53 .foreign_key(
54 &mut ForeignKey::create()
55 .name("FK_subscription_object_id")
56 .from(Subscription::Table, Subscription::SubscriptionId)
57 .to(
58 crate::m20230908_072257_init::Object::Table,
59 crate::m20230908_072257_init::Object::Oid,
60 )
61 .on_delete(ForeignKeyAction::Cascade)
62 .to_owned(),
63 )
64 .to_owned(),
65 )
66 .await?;
67 Ok(())
68 }
69
70 async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
71 drop_tables!(manager, Subscription);
73 Ok(())
74 }
75}
76
77#[derive(DeriveIden)]
78enum Subscription {
79 Table,
80 SubscriptionId,
81 Name,
82 Columns,
83 PlanPk,
84 DistributionKey,
85 Properties,
86 Definition,
87 SubscriptionFromName,
88}