Create monzo and flex accounts

This commit is contained in:
Joshua Coles 2024-10-15 21:17:39 +01:00
parent 3c3b6dc4e6
commit e3ed72c9b0
4 changed files with 57 additions and 2 deletions

2
.env
View File

@ -1 +1 @@
DATABASE_URL=postgres://postgres@localhost/logos_neu
DATABASE_URL=postgres://postgres@localhost/monzo_development

View File

@ -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),
]
}
}

View 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,
}

View File

@ -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;
}