add thumbnails model
This commit is contained in:
@@ -8,6 +8,7 @@ mod m20241029_235230_skills;
|
||||
mod m20241030_002154_jobs;
|
||||
mod m20241030_024340_projects;
|
||||
mod m20241030_024830_data;
|
||||
mod m20241106_005545_project_thumbnails;
|
||||
pub struct Migrator;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
@@ -15,6 +16,7 @@ impl MigratorTrait for Migrator {
|
||||
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
|
||||
vec![
|
||||
// inject-below
|
||||
Box::new(m20241106_005545_project_thumbnails::Migration),
|
||||
Box::new(m20241030_024830_data::Migration),
|
||||
Box::new(m20241030_024340_projects::Migration),
|
||||
Box::new(m20241030_002154_jobs::Migration),
|
||||
@@ -22,4 +24,4 @@ impl MigratorTrait for Migrator {
|
||||
Box::new(m20220101_000001_users::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,
|
||||
}
|
Reference in New Issue
Block a user