(toggl-portal): Add project <-> time_entry fk relation
This commit is contained in:
@@ -3,6 +3,7 @@ pub use sea_orm_migration::prelude::*;
|
||||
mod m20231101_172500_create_time_entry_table;
|
||||
mod m20231106_134950_create_clients;
|
||||
mod m20231106_195401_create_projects;
|
||||
mod m20231106_201029_add_time_entry_project_fk;
|
||||
|
||||
pub struct Migrator;
|
||||
|
||||
@@ -13,6 +14,7 @@ impl MigratorTrait for Migrator {
|
||||
Box::new(m20231101_172500_create_time_entry_table::Migration),
|
||||
Box::new(m20231106_134950_create_clients::Migration),
|
||||
Box::new(m20231106_195401_create_projects::Migration),
|
||||
Box::new(m20231106_201029_add_time_entry_project_fk::Migration),
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
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> {
|
||||
// Add foreign key to time entry table referencing project table
|
||||
manager
|
||||
.create_foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("time_entry_project_id")
|
||||
.from(TimeEntry::Table, TimeEntry::ProjectId)
|
||||
.to(Project::Table, Project::TogglId)
|
||||
.to_owned(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
// Drop foreign key
|
||||
manager
|
||||
.drop_foreign_key(ForeignKey::drop().name("time_entry_project_id").to_owned())
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum TimeEntry {
|
||||
Table,
|
||||
Id,
|
||||
ProjectId,
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum Project {
|
||||
Table,
|
||||
Id,
|
||||
TogglId,
|
||||
}
|
||||
Reference in New Issue
Block a user