add thumbnails model
This commit is contained in:
@@ -8,6 +8,7 @@ mod m20241029_235230_skills;
|
|||||||
mod m20241030_002154_jobs;
|
mod m20241030_002154_jobs;
|
||||||
mod m20241030_024340_projects;
|
mod m20241030_024340_projects;
|
||||||
mod m20241030_024830_data;
|
mod m20241030_024830_data;
|
||||||
|
mod m20241106_005545_project_thumbnails;
|
||||||
pub struct Migrator;
|
pub struct Migrator;
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
@@ -15,6 +16,7 @@ impl MigratorTrait for Migrator {
|
|||||||
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
|
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
|
||||||
vec![
|
vec![
|
||||||
// inject-below
|
// inject-below
|
||||||
|
Box::new(m20241106_005545_project_thumbnails::Migration),
|
||||||
Box::new(m20241030_024830_data::Migration),
|
Box::new(m20241030_024830_data::Migration),
|
||||||
Box::new(m20241030_024340_projects::Migration),
|
Box::new(m20241030_024340_projects::Migration),
|
||||||
Box::new(m20241030_002154_jobs::Migration),
|
Box::new(m20241030_002154_jobs::Migration),
|
||||||
|
69
migration/src/m20241106_005545_project_thumbnails.rs
Normal file
69
migration/src/m20241106_005545_project_thumbnails.rs
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
use loco_rs::schema::table_auto_tz;
|
||||||
|
use sea_orm_migration::{prelude::*, schema::*};
|
||||||
|
|
||||||
|
#[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_auto_tz(ProjectThumbnails::Table)
|
||||||
|
.primary_key(
|
||||||
|
Index::create()
|
||||||
|
.name("idx-project_thumbnails-refs-pk")
|
||||||
|
.table(ProjectThumbnails::Table)
|
||||||
|
.col(ProjectThumbnails::ProjectId)
|
||||||
|
.col(ProjectThumbnails::DataId)
|
||||||
|
,
|
||||||
|
)
|
||||||
|
.col(integer(ProjectThumbnails::ProjectId))
|
||||||
|
.col(integer(ProjectThumbnails::DataId))
|
||||||
|
.foreign_key(
|
||||||
|
ForeignKey::create()
|
||||||
|
.name("fk-project_thumbnails-projects")
|
||||||
|
.from(ProjectThumbnails::Table, ProjectThumbnails::ProjectId)
|
||||||
|
.to(Projects::Table, Projects::Id)
|
||||||
|
.on_delete(ForeignKeyAction::Cascade)
|
||||||
|
.on_update(ForeignKeyAction::Cascade),
|
||||||
|
)
|
||||||
|
.foreign_key(
|
||||||
|
ForeignKey::create()
|
||||||
|
.name("fk-project_thumbnails-data")
|
||||||
|
.from(ProjectThumbnails::Table, ProjectThumbnails::DataId)
|
||||||
|
.to(Data::Table, Data::Id)
|
||||||
|
.on_delete(ForeignKeyAction::Cascade)
|
||||||
|
.on_update(ForeignKeyAction::Cascade),
|
||||||
|
)
|
||||||
|
.to_owned(),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||||
|
manager
|
||||||
|
.drop_table(Table::drop().table(ProjectThumbnails::Table).to_owned())
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(DeriveIden)]
|
||||||
|
enum ProjectThumbnails {
|
||||||
|
Table,
|
||||||
|
ProjectId,
|
||||||
|
DataId,
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[derive(DeriveIden)]
|
||||||
|
enum Projects {
|
||||||
|
Table,
|
||||||
|
Id,
|
||||||
|
}
|
||||||
|
#[derive(DeriveIden)]
|
||||||
|
enum Data {
|
||||||
|
Table,
|
||||||
|
Id,
|
||||||
|
}
|
@@ -16,4 +16,22 @@ pub struct Model {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||||
pub enum Relation {}
|
pub enum Relation {
|
||||||
|
#[sea_orm(has_many = "super::project_thumbnails::Entity")]
|
||||||
|
ProjectThumbnails,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Related<super::project_thumbnails::Entity> for Entity {
|
||||||
|
fn to() -> RelationDef {
|
||||||
|
Relation::ProjectThumbnails.def()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Related<super::projects::Entity> for Entity {
|
||||||
|
fn to() -> RelationDef {
|
||||||
|
super::project_thumbnails::Relation::Projects.def()
|
||||||
|
}
|
||||||
|
fn via() -> Option<RelationDef> {
|
||||||
|
Some(super::project_thumbnails::Relation::Data.def().rev())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@@ -4,6 +4,7 @@ pub mod prelude;
|
|||||||
|
|
||||||
pub mod data;
|
pub mod data;
|
||||||
pub mod jobs;
|
pub mod jobs;
|
||||||
|
pub mod project_thumbnails;
|
||||||
pub mod projects;
|
pub mod projects;
|
||||||
pub mod skills;
|
pub mod skills;
|
||||||
pub mod users;
|
pub mod users;
|
||||||
|
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
pub use super::data::Entity as Data;
|
pub use super::data::Entity as Data;
|
||||||
pub use super::jobs::Entity as Jobs;
|
pub use super::jobs::Entity as Jobs;
|
||||||
|
pub use super::project_thumbnails::Entity as ProjectThumbnails;
|
||||||
pub use super::projects::Entity as Projects;
|
pub use super::projects::Entity as Projects;
|
||||||
pub use super::skills::Entity as Skills;
|
pub use super::skills::Entity as Skills;
|
||||||
pub use super::users::Entity as Users;
|
pub use super::users::Entity as Users;
|
||||||
|
47
src/models/_entities/project_thumbnails.rs
Normal file
47
src/models/_entities/project_thumbnails.rs
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0
|
||||||
|
|
||||||
|
use sea_orm::entity::prelude::*;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
|
||||||
|
#[sea_orm(table_name = "project_thumbnails")]
|
||||||
|
pub struct Model {
|
||||||
|
pub created_at: DateTimeWithTimeZone,
|
||||||
|
pub updated_at: DateTimeWithTimeZone,
|
||||||
|
#[sea_orm(primary_key, auto_increment = false)]
|
||||||
|
pub project_id: i32,
|
||||||
|
#[sea_orm(primary_key, auto_increment = false)]
|
||||||
|
pub data_id: i32,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||||
|
pub enum Relation {
|
||||||
|
#[sea_orm(
|
||||||
|
belongs_to = "super::data::Entity",
|
||||||
|
from = "Column::DataId",
|
||||||
|
to = "super::data::Column::Id",
|
||||||
|
on_update = "Cascade",
|
||||||
|
on_delete = "Cascade"
|
||||||
|
)]
|
||||||
|
Data,
|
||||||
|
#[sea_orm(
|
||||||
|
belongs_to = "super::projects::Entity",
|
||||||
|
from = "Column::ProjectId",
|
||||||
|
to = "super::projects::Column::Id",
|
||||||
|
on_update = "Cascade",
|
||||||
|
on_delete = "Cascade"
|
||||||
|
)]
|
||||||
|
Projects,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Related<super::data::Entity> for Entity {
|
||||||
|
fn to() -> RelationDef {
|
||||||
|
Relation::Data.def()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Related<super::projects::Entity> for Entity {
|
||||||
|
fn to() -> RelationDef {
|
||||||
|
Relation::Projects.def()
|
||||||
|
}
|
||||||
|
}
|
@@ -21,4 +21,22 @@ pub struct Model {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||||
pub enum Relation {}
|
pub enum Relation {
|
||||||
|
#[sea_orm(has_many = "super::project_thumbnails::Entity")]
|
||||||
|
ProjectThumbnails,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Related<super::project_thumbnails::Entity> for Entity {
|
||||||
|
fn to() -> RelationDef {
|
||||||
|
Relation::ProjectThumbnails.def()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Related<super::data::Entity> for Entity {
|
||||||
|
fn to() -> RelationDef {
|
||||||
|
super::project_thumbnails::Relation::Data.def()
|
||||||
|
}
|
||||||
|
fn via() -> Option<RelationDef> {
|
||||||
|
Some(super::project_thumbnails::Relation::Projects.def().rev())
|
||||||
|
}
|
||||||
|
}
|
@@ -4,3 +4,4 @@ pub mod skills;
|
|||||||
pub mod jobs;
|
pub mod jobs;
|
||||||
pub mod projects;
|
pub mod projects;
|
||||||
pub mod data;
|
pub mod data;
|
||||||
|
pub mod project_thumbnails;
|
||||||
|
7
src/models/project_thumbnails.rs
Normal file
7
src/models/project_thumbnails.rs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
use sea_orm::entity::prelude::*;
|
||||||
|
use super::_entities::project_thumbnails::{ActiveModel, Entity};
|
||||||
|
pub type ProjectThumbnails = Entity;
|
||||||
|
|
||||||
|
impl ActiveModelBehavior for ActiveModel {
|
||||||
|
// extend activemodel below (keep comment for generators)
|
||||||
|
}
|
@@ -19,3 +19,12 @@ struct ProjectWithTechnologies {
|
|||||||
pub download_url: Option<String>,
|
pub download_url: Option<String>,
|
||||||
pub visit_url: Option<String>,
|
pub visit_url: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum Category {
|
||||||
|
Web,
|
||||||
|
Mobile,
|
||||||
|
Desktop,
|
||||||
|
Game,
|
||||||
|
Api,
|
||||||
|
}
|
||||||
|
@@ -4,3 +4,4 @@ mod skills;
|
|||||||
mod jobs;
|
mod jobs;
|
||||||
mod projects;
|
mod projects;
|
||||||
mod data;
|
mod data;
|
||||||
|
mod project_thumbnails;
|
31
tests/models/project_thumbnails.rs
Normal file
31
tests/models/project_thumbnails.rs
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
use gabrielkaszewski_rs::app::App;
|
||||||
|
use loco_rs::testing;
|
||||||
|
use serial_test::serial;
|
||||||
|
|
||||||
|
macro_rules! configure_insta {
|
||||||
|
($($expr:expr),*) => {
|
||||||
|
let mut settings = insta::Settings::clone_current();
|
||||||
|
settings.set_prepend_module_to_snapshot(false);
|
||||||
|
let _guard = settings.bind_to_scope();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
#[serial]
|
||||||
|
async fn test_model() {
|
||||||
|
configure_insta!();
|
||||||
|
|
||||||
|
let boot = testing::boot_test::<App>().await.unwrap();
|
||||||
|
testing::seed::<App>(&boot.app_context.db).await.unwrap();
|
||||||
|
|
||||||
|
// query your model, e.g.:
|
||||||
|
//
|
||||||
|
// let item = models::posts::Model::find_by_pid(
|
||||||
|
// &boot.app_context.db,
|
||||||
|
// "11111111-1111-1111-1111-111111111111",
|
||||||
|
// )
|
||||||
|
// .await;
|
||||||
|
|
||||||
|
// snapshot the result:
|
||||||
|
// assert_debug_snapshot!(item);
|
||||||
|
}
|
Reference in New Issue
Block a user