diff --git a/migration/src/m20240719_00001_create_main_data_table.rs b/migration/src/m20240719_00001_create_main_data_table.rs index e045f5b..7afc208 100644 --- a/migration/src/m20240719_00001_create_main_data_table.rs +++ b/migration/src/m20240719_00001_create_main_data_table.rs @@ -1,6 +1,6 @@ use sea_orm::{EnumIter, Iterable}; use sea_orm_migration::prelude::extension::postgres::Type; -use sea_orm_migration::{manager, prelude::*}; +use sea_orm_migration::prelude::*; #[derive(DeriveMigrationName)] pub struct Migration; diff --git a/migration/src/m20240719_00002_create_long_data_table.rs b/migration/src/m20240719_00002_create_long_data_table.rs index bdbeff3..18f8614 100644 --- a/migration/src/m20240719_00002_create_long_data_table.rs +++ b/migration/src/m20240719_00002_create_long_data_table.rs @@ -13,7 +13,12 @@ impl MigrationTrait for Migration { Table::create() .table(LongData::Table) .if_not_exists() - .col(ColumnDef::new(LongData::SaveId).integer().not_null().primary_key()) + .col( + ColumnDef::new(LongData::SaveId) + .integer() + .not_null() + .primary_key(), + ) .col(ColumnDef::new(LongData::Len).string().not_null()) .col(ColumnDef::new(LongData::Text).string().not_null()) .foreign_key( diff --git a/sr_download/src/db/long_data.rs b/sr_download/src/db/long_data.rs index 4032600..1956ef5 100644 --- a/sr_download/src/db/long_data.rs +++ b/sr_download/src/db/long_data.rs @@ -12,6 +12,21 @@ pub struct Model { } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] -pub enum Relation {} +pub enum Relation { + #[sea_orm( + belongs_to = "super::main_data::Entity", + from = "Column::SaveId", + to = "super::main_data::Column::SaveId", + on_update = "Cascade", + on_delete = "Cascade" + )] + MainData, +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::MainData.def() + } +} impl ActiveModelBehavior for ActiveModel {} diff --git a/sr_download/src/db/main_data.rs b/sr_download/src/db/main_data.rs index 3a0526a..1fbdfa7 100644 --- a/sr_download/src/db/main_data.rs +++ b/sr_download/src/db/main_data.rs @@ -1,6 +1,6 @@ //! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.15 -use super::sea_orm_active_enums::SaveTypeEnum; +use super::sea_orm_active_enums::SaveType; use sea_orm::entity::prelude::*; #[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)] @@ -8,13 +8,22 @@ use sea_orm::entity::prelude::*; pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub save_id: i32, - pub save_type: SaveTypeEnum, + pub save_type: SaveType, pub blake_hash: String, pub len: i32, pub short_data: Option, } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] -pub enum Relation {} +pub enum Relation { + #[sea_orm(has_many = "super::long_data::Entity")] + LongData, +} + +impl Related for Entity { + fn to() -> RelationDef { + Relation::LongData.def() + } +} impl ActiveModelBehavior for ActiveModel {} diff --git a/sr_download/src/db/sea_orm_active_enums.rs b/sr_download/src/db/sea_orm_active_enums.rs index 2e05887..9e497fe 100644 --- a/sr_download/src/db/sea_orm_active_enums.rs +++ b/sr_download/src/db/sea_orm_active_enums.rs @@ -3,8 +3,8 @@ use sea_orm::entity::prelude::*; #[derive(Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum)] -#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "save_type_enum")] -pub enum SaveTypeEnum { +#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "save_type")] +pub enum SaveType { #[sea_orm(string_value = "none")] None, #[sea_orm(string_value = "save")]