diff --git a/migration/src/lib.rs b/migration/src/lib.rs index 606065e..094341b 100644 --- a/migration/src/lib.rs +++ b/migration/src/lib.rs @@ -4,6 +4,7 @@ mod m20220101_000001_create_table; mod m20221030_192706_add_last_update; mod m20221102_232244_add_join_table; mod m20221102_232858_remove_unused_columns; +mod m20221106_211436_remove_query_x; pub struct Migrator; @@ -15,6 +16,7 @@ impl MigratorTrait for Migrator { Box::new(m20221030_192706_add_last_update::Migration), Box::new(m20221102_232244_add_join_table::Migration), Box::new(m20221102_232858_remove_unused_columns::Migration), + Box::new(m20221106_211436_remove_query_x::Migration), ] } } diff --git a/migration/src/m20221106_211436_remove_query_x.rs b/migration/src/m20221106_211436_remove_query_x.rs new file mode 100644 index 0000000..9468535 --- /dev/null +++ b/migration/src/m20221106_211436_remove_query_x.rs @@ -0,0 +1,87 @@ +use sea_orm_migration::prelude::*; + +#[derive(DeriveMigrationName)] +pub struct Migration; + +#[async_trait::async_trait] +impl MigrationTrait for Migration { + async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { + manager + .alter_table( + Table::alter() + .table(Metrics::Table) + .drop_column(Metrics::QueryX) + .to_owned() + ).await?; + + manager + .alter_table( + Table::alter() + .table(Metrics::Table) + .rename_column(Metrics::QueryY, Metrics::Query) + .to_owned() + ).await?; + + manager + .alter_table( + Table::alter() + .table(Panels::Table) + .drop_column(Panels::Timeserie) + .to_owned() + ).await?; + + Ok(()) + } + + async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { + manager + .alter_table( + Table::alter() + .table(Metrics::Table) + .rename_column(Metrics::Query, Metrics::QueryY) + .to_owned() + ).await?; + + manager. + alter_table( + Table::alter() + .table(Metrics::Table) + .add_column( + ColumnDef::new(Metrics::QueryX) + .float() + .not_null() + .default(0.0) + ) + .to_owned() + ).await?; + + manager. + alter_table( + Table::alter() + .table(Panels::Table) + .add_column( + ColumnDef::new(Panels::Timeserie) + .boolean() + .not_null() + .default(true) + ) + .to_owned() + ).await?; + + Ok(()) + } +} + +#[derive(Iden)] +enum Metrics { + Table, + QueryX, + QueryY, + Query, +} + +#[derive(Iden)] +enum Panels { + Table, + Timeserie, +}