feat: Implement database migration framework with initial migrations for organizations, workspaces, agents, virtual hosts, upstreams, certificates, and users

This commit is contained in:
GW_MC
2026-03-03 04:31:06 +00:00
parent 2e9ad4fc21
commit 7d9285ba44
15 changed files with 785 additions and 23 deletions

View File

@@ -0,0 +1,88 @@
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(Workspaces::Table)
.if_not_exists()
.col(
ColumnDef::new(Workspaces::Id)
.uuid()
.not_null()
.primary_key(),
)
.col(
ColumnDef::new(Workspaces::OrganizationId)
.uuid()
.not_null(),
)
.col(ColumnDef::new(Workspaces::Name).string().not_null())
.col(
ColumnDef::new(Workspaces::Slug)
.string()
.not_null(),
)
.col(
ColumnDef::new(Workspaces::CreatedAt)
.timestamp_with_time_zone()
.not_null(),
)
.col(
ColumnDef::new(Workspaces::UpdatedAt)
.timestamp_with_time_zone()
.not_null(),
)
.foreign_key(
ForeignKey::create()
.name("fk_workspace_organization")
.from(Workspaces::Table, Workspaces::OrganizationId)
.to(Organizations::Table, Organizations::Id)
.on_delete(ForeignKeyAction::Cascade),
)
.to_owned(),
)
.await?;
// Create unique index on organization_id + slug
manager
.create_index(
Index::create()
.unique()
.name("idx_workspaces_org_slug")
.table(Workspaces::Table)
.col(Workspaces::OrganizationId)
.col(Workspaces::Slug)
.to_owned(),
)
.await
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(Workspaces::Table).to_owned())
.await
}
}
#[derive(DeriveIden)]
enum Workspaces {
Table,
Id,
OrganizationId,
Name,
Slug,
CreatedAt,
UpdatedAt,
}
#[derive(DeriveIden)]
enum Organizations {
Table,
Id,
}