Create monzo and flex accounts
This commit is contained in:
parent
3c3b6dc4e6
commit
e3ed72c9b0
2
.env
2
.env
@ -1 +1 @@
|
||||
DATABASE_URL=postgres://postgres@localhost/logos_neu
|
||||
DATABASE_URL=postgres://postgres@localhost/monzo_development
|
||||
|
||||
@ -5,6 +5,7 @@ mod m20240529_195030_add_transaction_identity_hash;
|
||||
mod m20240603_162500_make_title_optional;
|
||||
mod m20241015_195220_add_account_to_transactions;
|
||||
mod m20241015_200222_add_expenditure_transaction_fk;
|
||||
mod m20241015_200652_add_accounts;
|
||||
|
||||
pub struct Migrator;
|
||||
|
||||
@ -21,6 +22,7 @@ impl MigratorTrait for Migrator {
|
||||
Box::new(m20240603_162500_make_title_optional::Migration),
|
||||
Box::new(m20241015_195220_add_account_to_transactions::Migration),
|
||||
Box::new(m20241015_200222_add_expenditure_transaction_fk::Migration),
|
||||
Box::new(m20241015_200652_add_accounts::Migration),
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
53
migration/src/m20241015_200652_add_accounts.rs
Normal file
53
migration/src/m20241015_200652_add_accounts.rs
Normal file
@ -0,0 +1,53 @@
|
||||
use sea_orm_migration::{prelude::*, schema::*};
|
||||
use crate::sea_orm::sqlx;
|
||||
|
||||
#[derive(DeriveMigrationName)]
|
||||
pub struct Migration;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigrationTrait for Migration {
|
||||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager.exec_stmt(
|
||||
InsertStatement::new()
|
||||
.into_table(Account::Table)
|
||||
.columns(vec![Account::Name])
|
||||
.values_panic(["Monzo".into()])
|
||||
.values_panic(["Flex".into()])
|
||||
.to_owned()
|
||||
).await?;
|
||||
|
||||
let id: i32 = manager.get_connection().query_one(
|
||||
sea_orm::Statement::from_string(
|
||||
manager.get_database_backend(),
|
||||
"SELECT id FROM account WHERE name = 'Monzo'",
|
||||
)
|
||||
).await?.expect("Monzo account not found").try_get_by_index(0)?;
|
||||
|
||||
manager.exec_stmt(
|
||||
UpdateStatement::new()
|
||||
.table(Transaction::Table)
|
||||
.values([(Transaction::AccountId, id.into())])
|
||||
.to_owned()
|
||||
).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
// This is a data creation migration, so we do not roll back the migration
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum Account {
|
||||
Table,
|
||||
Id,
|
||||
Name,
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum Transaction {
|
||||
Table,
|
||||
AccountId,
|
||||
}
|
||||
@ -3,7 +3,7 @@ mod headings {
|
||||
#[allow(unused_imports)]
|
||||
pub use super::super::ingestion_logic::headings::*;
|
||||
|
||||
// Additional FLex headings
|
||||
// Additional Flex headings
|
||||
pub const MONEY_OUT: usize = 16;
|
||||
pub const MONEY_IN: usize = 17;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user