Make title optional in db
This commit is contained in:
parent
4bb9f2813d
commit
6c5d3910dc
@ -11,7 +11,7 @@ pub struct Model {
|
|||||||
pub transaction_type: String,
|
pub transaction_type: String,
|
||||||
pub total_amount: Decimal,
|
pub total_amount: Decimal,
|
||||||
pub timestamp: DateTime,
|
pub timestamp: DateTime,
|
||||||
pub title: String,
|
pub title: Option<String>,
|
||||||
pub emoji: Option<String>,
|
pub emoji: Option<String>,
|
||||||
pub notes: Option<String>,
|
pub notes: Option<String>,
|
||||||
pub receipt: Option<String>,
|
pub receipt: Option<String>,
|
||||||
|
|||||||
12
justfile
Executable file
12
justfile
Executable file
@ -0,0 +1,12 @@
|
|||||||
|
#!/usr/bin/env just --justfile
|
||||||
|
|
||||||
|
generate-migration:
|
||||||
|
sea-orm-cli migrate generate $1
|
||||||
|
|
||||||
|
migrate:
|
||||||
|
sea-orm-cli migrate up
|
||||||
|
|
||||||
|
generate-entities:
|
||||||
|
sea-orm-cli generate entity --with-serde both \
|
||||||
|
-l -o entity/src \
|
||||||
|
--ignore-tables monzo_ingestion_seaql_migrations
|
||||||
@ -2,6 +2,7 @@ pub use sea_orm_migration::prelude::*;
|
|||||||
|
|
||||||
pub mod m20230904_141851_create_monzo_tables;
|
pub mod m20230904_141851_create_monzo_tables;
|
||||||
mod m20240529_195030_add_transaction_identity_hash;
|
mod m20240529_195030_add_transaction_identity_hash;
|
||||||
|
mod m20240603_162500_make_title_optional;
|
||||||
|
|
||||||
pub struct Migrator;
|
pub struct Migrator;
|
||||||
|
|
||||||
@ -15,6 +16,7 @@ impl MigratorTrait for Migrator {
|
|||||||
vec![
|
vec![
|
||||||
Box::new(m20230904_141851_create_monzo_tables::Migration),
|
Box::new(m20230904_141851_create_monzo_tables::Migration),
|
||||||
Box::new(m20240529_195030_add_transaction_identity_hash::Migration),
|
Box::new(m20240529_195030_add_transaction_identity_hash::Migration),
|
||||||
|
Box::new(m20240603_162500_make_title_optional::Migration),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
47
migration/src/m20240603_162500_make_title_optional.rs
Normal file
47
migration/src/m20240603_162500_make_title_optional.rs
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
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(
|
||||||
|
TableAlterStatement::new()
|
||||||
|
.table(Transaction::Table)
|
||||||
|
.modify_column(ColumnDef::new(Transaction::Title).string().null())
|
||||||
|
.to_owned()
|
||||||
|
).await?;
|
||||||
|
|
||||||
|
// Set all empty string titles to null
|
||||||
|
manager.get_connection().execute_unprepared(r#"
|
||||||
|
update transaction
|
||||||
|
set title = null
|
||||||
|
where title = ''
|
||||||
|
"#).await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||||
|
// Set all null titles to empty string when reverting
|
||||||
|
manager.get_connection().execute_unprepared(r#"
|
||||||
|
update transaction
|
||||||
|
set title = ''
|
||||||
|
where title is null
|
||||||
|
"#).await?;
|
||||||
|
|
||||||
|
manager.alter_table(
|
||||||
|
TableAlterStatement::new()
|
||||||
|
.table(Transaction::Table)
|
||||||
|
.modify_column(ColumnDef::new(Transaction::Title).string().not_null())
|
||||||
|
.to_owned()
|
||||||
|
).await
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(DeriveIden)]
|
||||||
|
enum Transaction {
|
||||||
|
Table,
|
||||||
|
Title,
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user