You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
fast-insiders/server/migration/src/m20230112_160440_create_tra...

79 lines
2.7 KiB

use crate::m20230112_115856_create_company_table as company;
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)
.integer()
.not_null()
.auto_increment()
.primary_key(),
)
.col(ColumnDef::new(Transaction::CompanyId).integer().not_null())
.col(
ColumnDef::new(Transaction::ForeignId)
.string()
.not_null()
.unique_key(),
)
.col(ColumnDef::new(Transaction::DatePublished).date().not_null())
.col(ColumnDef::new(Transaction::DateExecuted).date().not_null())
.col(ColumnDef::new(Transaction::Person).text().not_null())
.col(ColumnDef::new(Transaction::Exchange).string().not_null())
.col(ColumnDef::new(Transaction::Nature).string().not_null())
.col(ColumnDef::new(Transaction::Isin).string())
.col(ColumnDef::new(Transaction::Instrument).string().not_null())
.col(ColumnDef::new(Transaction::Volume).integer().not_null())
.col(ColumnDef::new(Transaction::UnitPrice).float().not_null())
.to_owned(),
)
.await?;
manager
.create_foreign_key(
ForeignKey::create()
.name("FK_transaction_to_company")
.from(Transaction::Table, Transaction::CompanyId)
.to(company::Company::Table, company::Company::Id)
.on_update(ForeignKeyAction::Cascade)
.on_delete(ForeignKeyAction::Cascade)
.to_owned(),
)
.await
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(Transaction::Table).to_owned())
.await
}
}
/// Learn more at https://docs.rs/sea-query#iden
#[derive(Iden)]
enum Transaction {
Table,
Id,
CompanyId,
ForeignId,
DatePublished,
DateExecuted,
Person,
Exchange,
Nature,
Isin,
Instrument,
Volume,
UnitPrice,
}