diff --git a/.env b/.env index eaf3698..5a6adb9 100644 --- a/.env +++ b/.env @@ -1 +1 @@ -DATABASE_URL=postgres://postgres@localhost/logos_neu +DATABASE_URL=postgres://postgres@localhost/monzo_development diff --git a/migration/src/lib.rs b/migration/src/lib.rs index dc30a72..d12e5c7 100644 --- a/migration/src/lib.rs +++ b/migration/src/lib.rs @@ -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), ] } } diff --git a/migration/src/m20241015_200652_add_accounts.rs b/migration/src/m20241015_200652_add_accounts.rs new file mode 100644 index 0000000..d052244 --- /dev/null +++ b/migration/src/m20241015_200652_add_accounts.rs @@ -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, +} diff --git a/src/ingestion/flex.rs b/src/ingestion/flex.rs index 165de5c..f9c3715 100644 --- a/src/ingestion/flex.rs +++ b/src/ingestion/flex.rs @@ -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; }