Initial work

This commit is contained in:
2023-09-04 15:29:21 +01:00
commit 554e645f92
15 changed files with 3478 additions and 0 deletions
+12
View File
@@ -0,0 +1,12 @@
pub use sea_orm_migration::prelude::*;
pub mod m20230904_141851_create_monzo_tables;
pub struct Migrator;
#[async_trait::async_trait]
impl MigratorTrait for Migrator {
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
vec![Box::new(m20230904_141851_create_monzo_tables::Migration)]
}
}
@@ -0,0 +1,114 @@
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.create_table(
Table::create()
.table(Transaction::Table)
.if_not_exists()
.col(
ColumnDef::new(Transaction::Id)
.string()
.not_null()
.primary_key(),
)
.col(
ColumnDef::new(Transaction::TransactionType)
.string()
.not_null(),
)
.col(
ColumnDef::new(Transaction::TotalAmount)
.decimal()
.not_null(),
)
.col(
ColumnDef::new(Transaction::Timestamp)
.timestamp()
.not_null(),
)
.col(
ColumnDef::new(Transaction::Title)
.string()
.not_null(),
)
.col(
ColumnDef::new(Transaction::Emoji)
.string(),
)
.col(
ColumnDef::new(Transaction::Notes)
.string(),
)
.col(
ColumnDef::new(Transaction::Receipt)
.string(),
)
.col(
ColumnDef::new(Transaction::Description)
.string(),
)
.to_owned()
).await?;
manager
.create_table(
Table::create()
.table(Expenditure::Table)
.if_not_exists()
.col(
ColumnDef::new(Expenditure::TransactionId)
.integer()
.not_null(),
)
.col(ColumnDef::new(Expenditure::Category).string().not_null())
.primary_key(
Index::create()
.col(Expenditure::TransactionId)
.col(Expenditure::Category),
)
.col(ColumnDef::new(Expenditure::Amount).decimal().not_null())
.to_owned(),
).await?;
Ok(())
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(Expenditure::Table).to_owned())
.await?;
manager
.drop_table(Table::drop().table(Transaction::Table).to_owned())
.await?;
Ok(())
}
}
#[derive(DeriveIden)]
enum Transaction {
Table,
Id,
TransactionType,
Timestamp,
Title,
Emoji,
Notes,
Receipt,
TotalAmount,
Description,
}
#[derive(DeriveIden)]
enum Expenditure {
Table,
Category,
Amount,
TransactionId,
}
+6
View File
@@ -0,0 +1,6 @@
use sea_orm_migration::prelude::*;
#[async_std::main]
async fn main() {
cli::run_cli(migration::Migrator).await;
}