84 lines
2.6 KiB
Rust
84 lines
2.6 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(Upstreams::Table)
|
|
.if_not_exists()
|
|
.col(
|
|
ColumnDef::new(Upstreams::Id)
|
|
.uuid()
|
|
.not_null()
|
|
.primary_key(),
|
|
)
|
|
.col(
|
|
ColumnDef::new(Upstreams::WorkspaceId)
|
|
.uuid()
|
|
.not_null(),
|
|
)
|
|
.col(ColumnDef::new(Upstreams::Name).string().not_null())
|
|
.col(
|
|
ColumnDef::new(Upstreams::Algorithm)
|
|
.string()
|
|
.not_null(),
|
|
)
|
|
.col(ColumnDef::new(Upstreams::Servers).json())
|
|
.col(ColumnDef::new(Upstreams::HealthCheck).json())
|
|
.col(ColumnDef::new(Upstreams::KeepaliveConnections).integer())
|
|
.col(ColumnDef::new(Upstreams::KeepaliveTimeout).integer())
|
|
.col(
|
|
ColumnDef::new(Upstreams::CreatedAt)
|
|
.timestamp_with_time_zone()
|
|
.not_null(),
|
|
)
|
|
.col(
|
|
ColumnDef::new(Upstreams::UpdatedAt)
|
|
.timestamp_with_time_zone()
|
|
.not_null(),
|
|
)
|
|
.foreign_key(
|
|
ForeignKey::create()
|
|
.name("fk_upstream_workspace")
|
|
.from(Upstreams::Table, Upstreams::WorkspaceId)
|
|
.to(Workspaces::Table, Workspaces::Id)
|
|
.on_delete(ForeignKeyAction::Cascade),
|
|
)
|
|
.to_owned(),
|
|
)
|
|
.await
|
|
}
|
|
|
|
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
|
manager
|
|
.drop_table(Table::drop().table(Upstreams::Table).to_owned())
|
|
.await
|
|
}
|
|
}
|
|
|
|
#[derive(DeriveIden)]
|
|
enum Upstreams {
|
|
Table,
|
|
Id,
|
|
WorkspaceId,
|
|
Name,
|
|
Algorithm,
|
|
Servers,
|
|
HealthCheck,
|
|
KeepaliveConnections,
|
|
KeepaliveTimeout,
|
|
CreatedAt,
|
|
UpdatedAt,
|
|
}
|
|
|
|
#[derive(DeriveIden)]
|
|
enum Workspaces {
|
|
Table,
|
|
Id,
|
|
}
|