feat: add location and proxy host entities with migrations
This commit is contained in:
@@ -15,6 +15,8 @@ impl MigratorTrait for Migrator {
|
||||
Box::new(m20251011_000003_create_user_identity_table::Migration),
|
||||
Box::new(m20251223_000004_create_upstream_table::Migration),
|
||||
Box::new(m20251223_000005_create_upstream_target_table::Migration),
|
||||
Box::new(m20260102_000006_create_proxy_table::Migration),
|
||||
Box::new(m20260102_000007_create_location_table::Migration),
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,3 +3,5 @@ pub mod m20251011_000002_create_user_table;
|
||||
pub mod m20251011_000003_create_user_identity_table;
|
||||
pub mod m20251223_000004_create_upstream_table;
|
||||
pub mod m20251223_000005_create_upstream_target_table;
|
||||
pub mod m20260102_000006_create_proxy_table;
|
||||
pub mod m20260102_000007_create_location_table;
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
use sea_orm_migration::{prelude::*, schema::*};
|
||||
|
||||
#[derive(DeriveMigrationName)]
|
||||
pub struct Migration;
|
||||
|
||||
#[forbid(dead_code)]
|
||||
#[derive(DeriveIden)]
|
||||
pub enum ProxyHost {
|
||||
Table,
|
||||
Id,
|
||||
Name,
|
||||
Domain,
|
||||
Scheme,
|
||||
ListenPort,
|
||||
ForwardScheme,
|
||||
ForwardHost,
|
||||
ForwardPort,
|
||||
PreserveHostHeader,
|
||||
EnableWebsocket,
|
||||
Enabled,
|
||||
Meta,
|
||||
DefaultUpstreamId,
|
||||
CreatedBy,
|
||||
CreatedAt,
|
||||
UpdatedAt,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigrationTrait for Migration {
|
||||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(ProxyHost::Table)
|
||||
.if_not_exists()
|
||||
.col(pk_uuid(ProxyHost::Id))
|
||||
.col(ColumnDef::new(ProxyHost::Name).string().null())
|
||||
.col(ColumnDef::new(ProxyHost::Domain).string().not_null())
|
||||
.col(
|
||||
ColumnDef::new(ProxyHost::Scheme)
|
||||
.string()
|
||||
.default("http")
|
||||
.not_null(),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(ProxyHost::ListenPort)
|
||||
.integer()
|
||||
.default(80)
|
||||
.not_null(),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(ProxyHost::ForwardScheme)
|
||||
.string()
|
||||
.default("http")
|
||||
.not_null(),
|
||||
)
|
||||
.col(ColumnDef::new(ProxyHost::ForwardHost).string().null())
|
||||
.col(ColumnDef::new(ProxyHost::ForwardPort).integer().null())
|
||||
.col(
|
||||
ColumnDef::new(ProxyHost::PreserveHostHeader)
|
||||
.boolean()
|
||||
.default(false)
|
||||
.not_null(),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(ProxyHost::EnableWebsocket)
|
||||
.boolean()
|
||||
.default(false)
|
||||
.not_null(),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(ProxyHost::Enabled)
|
||||
.boolean()
|
||||
.default(true)
|
||||
.not_null(),
|
||||
)
|
||||
.col(ColumnDef::new(ProxyHost::Meta).json_binary().null())
|
||||
.col(ColumnDef::new(ProxyHost::DefaultUpstreamId).uuid().null())
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fk-proxy-host-default-upstream-id")
|
||||
.from(ProxyHost::Table, ProxyHost::DefaultUpstreamId)
|
||||
.to(
|
||||
super::m20251223_000004_create_upstream_table::Upstream::Table,
|
||||
super::m20251223_000004_create_upstream_table::Upstream::Id,
|
||||
)
|
||||
.on_delete(ForeignKeyAction::SetNull)
|
||||
.on_update(ForeignKeyAction::Cascade),
|
||||
)
|
||||
.col(ColumnDef::new(ProxyHost::CreatedBy).uuid().null())
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fk-proxy-host-created-by")
|
||||
.from(ProxyHost::Table, ProxyHost::CreatedBy)
|
||||
.to(
|
||||
super::m20251011_000002_create_user_table::User::Table,
|
||||
super::m20251011_000002_create_user_table::User::Id,
|
||||
)
|
||||
.on_delete(ForeignKeyAction::SetNull)
|
||||
.on_update(ForeignKeyAction::Cascade),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(ProxyHost::CreatedAt)
|
||||
.timestamp()
|
||||
.default(SimpleExpr::Keyword(Keyword::CurrentTimestamp))
|
||||
.not_null(),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(ProxyHost::UpdatedAt)
|
||||
.timestamp()
|
||||
.default(SimpleExpr::Keyword(Keyword::CurrentTimestamp))
|
||||
.not_null(),
|
||||
)
|
||||
.to_owned(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.drop_table(Table::drop().table(ProxyHost::Table).to_owned())
|
||||
.await
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
use sea_orm_migration::{prelude::*, schema::*};
|
||||
|
||||
#[derive(DeriveMigrationName)]
|
||||
pub struct Migration;
|
||||
|
||||
#[forbid(dead_code)]
|
||||
#[derive(DeriveIden)]
|
||||
pub enum Location {
|
||||
Table,
|
||||
Id,
|
||||
HostId,
|
||||
Path,
|
||||
MatchType,
|
||||
Order,
|
||||
UpstreamId,
|
||||
ProxyPassProtocol,
|
||||
ProxyPassHost,
|
||||
ProxyPassPort,
|
||||
PreserveHostHeader,
|
||||
AllowedMethods,
|
||||
CustomConfig,
|
||||
Enabled,
|
||||
CreatedAt,
|
||||
UpdatedAt,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigrationTrait for Migration {
|
||||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(Location::Table)
|
||||
.if_not_exists()
|
||||
.col(pk_uuid(Location::Id))
|
||||
.col(ColumnDef::new(Location::HostId).uuid().not_null())
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fk-location-host-id")
|
||||
.from(Location::Table, Location::HostId)
|
||||
.to(
|
||||
super::m20260102_000006_create_proxy_table::ProxyHost::Table,
|
||||
super::m20260102_000006_create_proxy_table::ProxyHost::Id,
|
||||
)
|
||||
.on_delete(ForeignKeyAction::Cascade)
|
||||
.on_update(ForeignKeyAction::Cascade),
|
||||
)
|
||||
.col(ColumnDef::new(Location::Path).string().not_null())
|
||||
.col(
|
||||
ColumnDef::new(Location::MatchType)
|
||||
.string()
|
||||
.default("prefix")
|
||||
.not_null(),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(Location::Order)
|
||||
.integer()
|
||||
.default(0)
|
||||
.not_null(),
|
||||
)
|
||||
.col(ColumnDef::new(Location::UpstreamId).uuid().null())
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fk-location-upstream-id")
|
||||
.from(Location::Table, Location::UpstreamId)
|
||||
.to(
|
||||
super::m20251223_000004_create_upstream_table::Upstream::Table,
|
||||
super::m20251223_000004_create_upstream_table::Upstream::Id,
|
||||
)
|
||||
.on_delete(ForeignKeyAction::SetNull)
|
||||
.on_update(ForeignKeyAction::Cascade),
|
||||
)
|
||||
.col(ColumnDef::new(Location::ProxyPassProtocol).string().null())
|
||||
.col(ColumnDef::new(Location::ProxyPassHost).string().null())
|
||||
.col(ColumnDef::new(Location::ProxyPassPort).integer().null())
|
||||
.col(
|
||||
ColumnDef::new(Location::PreserveHostHeader)
|
||||
.boolean()
|
||||
.null(),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(Location::AllowedMethods)
|
||||
.json_binary()
|
||||
.null(),
|
||||
)
|
||||
.col(ColumnDef::new(Location::CustomConfig).text().null())
|
||||
.col(
|
||||
ColumnDef::new(Location::Enabled)
|
||||
.boolean()
|
||||
.default(true)
|
||||
.not_null(),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(Location::CreatedAt)
|
||||
.timestamp()
|
||||
.default(SimpleExpr::Keyword(Keyword::CurrentTimestamp))
|
||||
.not_null(),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(Location::UpdatedAt)
|
||||
.timestamp()
|
||||
.default(SimpleExpr::Keyword(Keyword::CurrentTimestamp))
|
||||
.not_null(),
|
||||
)
|
||||
.to_owned(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.drop_table(Table::drop().table(Location::Table).to_owned())
|
||||
.await
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user