65 lines
1.8 KiB
Rust
65 lines
1.8 KiB
Rust
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,
|
|
}
|