Skip to content

Commit

Permalink
fix: fix system_parameter value column type and remove unnecessary FK…
Browse files Browse the repository at this point in the history
…s in mysql
  • Loading branch information
yezizp2012 committed Jul 2, 2024
1 parent 761f142 commit a2345f3
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/meta/model_v2/migration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ mod m20240506_112555_subscription_partial_ckpt;
mod m20240525_090457_secret;
mod m20240617_070131_index_column_properties;
mod m20240618_072634_function_compressed_binary;
mod m20240702_080451_system_param_value;
mod m20240702_084927_unnecessary_fk;

pub struct Migrator;

Expand All @@ -31,6 +33,8 @@ impl MigratorTrait for Migrator {
Box::new(m20240525_090457_secret::Migration),
Box::new(m20240618_072634_function_compressed_binary::Migration),
Box::new(m20240617_070131_index_column_properties::Migration),
Box::new(m20240702_080451_system_param_value::Migration),
Box::new(m20240702_084927_unnecessary_fk::Migration),
]
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
use sea_orm_migration::prelude::*;

use crate::sea_orm::DbBackend;

#[derive(DeriveMigrationName)]
pub struct Migration;

#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
match manager.get_database_backend() {
DbBackend::MySql => {
manager
.alter_table(
Table::alter()
.table(SystemParameter::Table)
.modify_column(ColumnDef::new(SystemParameter::Value).text().not_null())
.to_owned(),
)
.await?;
}
_ => {}
}
Ok(())
}

async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
match manager.get_database_backend() {
DbBackend::MySql => {
manager
.alter_table(
Table::alter()
.table(SystemParameter::Table)
.modify_column(
ColumnDef::new(SystemParameter::Value).string().not_null(),
)
.to_owned(),
)
.await?;
}
_ => {}
}
Ok(())
}
}

#[derive(DeriveIden)]
enum SystemParameter {
Table,
Value,
}
41 changes: 41 additions & 0 deletions src/meta/model_v2/migration/src/m20240702_084927_unnecessary_fk.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use sea_orm_migration::prelude::*;

use crate::sea_orm::DbBackend;

#[derive(DeriveMigrationName)]
pub struct Migration;

#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
match manager.get_database_backend() {
DbBackend::MySql => {
manager
.alter_table(
Table::alter()
.table(Alias::new("sink"))
.drop_foreign_key(Alias::new("FK_sink_connection_id"))
.drop_foreign_key(Alias::new("FK_sink_target_table_id"))
.to_owned(),
)
.await?;
manager
.alter_table(
Table::alter()
.table(Alias::new("source"))
.drop_foreign_key(Alias::new("FK_source_connection_id"))
.to_owned(),
)
.await?;
}
_ => {}
}

Ok(())
}

async fn down(&self, _manager: &SchemaManager) -> Result<(), DbErr> {
// Do nothing.
Ok(())
}
}

0 comments on commit a2345f3

Please sign in to comment.