feat: Implement database migration framework with initial migrations for organizations, workspaces, agents, virtual hosts, upstreams, certificates, and users
This commit is contained in:
83
migration/src/m20240301_000005_create_upstreams.rs
Normal file
83
migration/src/m20240301_000005_create_upstreams.rs
Normal file
@@ -0,0 +1,83 @@
|
||||
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,
|
||||
}
|
||||
Reference in New Issue
Block a user