(toggl-portal): Add projects to database
This commit is contained in:
@@ -2,6 +2,7 @@ pub use sea_orm_migration::prelude::*;
|
||||
|
||||
mod m20231101_172500_create_time_entry_table;
|
||||
mod m20231106_134950_create_clients;
|
||||
mod m20231106_195401_create_projects;
|
||||
|
||||
pub struct Migrator;
|
||||
|
||||
@@ -11,6 +12,7 @@ impl MigratorTrait for Migrator {
|
||||
vec![
|
||||
Box::new(m20231101_172500_create_time_entry_table::Migration),
|
||||
Box::new(m20231106_134950_create_clients::Migration),
|
||||
Box::new(m20231106_195401_create_projects::Migration),
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
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(Project::Table)
|
||||
.if_not_exists()
|
||||
.col(ColumnDef::new(Project::Id).integer().not_null())
|
||||
.col(ColumnDef::new(Project::TogglId).big_unsigned().not_null())
|
||||
.col(
|
||||
ColumnDef::new(Project::WorkspaceId)
|
||||
.big_unsigned()
|
||||
.not_null(),
|
||||
)
|
||||
.col(ColumnDef::new(Project::ClientId).integer())
|
||||
.col(ColumnDef::new(Project::Name).string().not_null())
|
||||
.col(ColumnDef::new(Project::Active).boolean().not_null())
|
||||
.col(ColumnDef::new(Project::RawJson).json_binary().not_null())
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
// Create foreign key
|
||||
manager.create_foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("project_client_id")
|
||||
.from(Project::Table, Project::ClientId)
|
||||
.to(Client::Table, Client::Id)
|
||||
.to_owned(),
|
||||
).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.drop_table(Table::drop().table(Project::Table).to_owned())
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum Project {
|
||||
Table,
|
||||
Id,
|
||||
TogglId,
|
||||
WorkspaceId,
|
||||
ClientId,
|
||||
Name,
|
||||
Active,
|
||||
RawJson,
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum Client {
|
||||
Table,
|
||||
Id,
|
||||
}
|
||||
Reference in New Issue
Block a user