Refactor database schema: Remove access list and related entities, add editing session and edit operation entities
- Deleted `access_list_entry`, `location`, `proxy_host`, `proxy_host_access_list`, `session`, `stream_service`, `stream_service_access_list` entities and their corresponding migration files. - Introduced `editing_session` and `edit_operation` entities with appropriate fields and relationships. - Updated `mod.rs` and `prelude.rs` to reflect the changes in the entity structure. - Adjusted migration files to remove obsolete migrations and include new migrations for the editing session and edit operation tables.
This commit is contained in:
@@ -15,13 +15,7 @@ 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(m20251223_000006_create_proxy_host_table::Migration),
|
||||
Box::new(m20251223_000007_create_location_table::Migration),
|
||||
Box::new(m20251223_000008_create_stream_service_table::Migration),
|
||||
Box::new(m20251223_000009_create_access_list_table::Migration),
|
||||
Box::new(m20251223_000010_create_access_list_entry_table::Migration),
|
||||
Box::new(m20251223_000011_create_proxy_host_access_list_table::Migration),
|
||||
Box::new(m20251223_000012_create_stream_service_access_list_table::Migration),
|
||||
Box::new(m20251230_000006_create_editing_session_table::Migration),
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,10 +3,4 @@ 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 m20251223_000006_create_proxy_host_table;
|
||||
pub mod m20251223_000007_create_location_table;
|
||||
pub mod m20251223_000008_create_stream_service_table;
|
||||
pub mod m20251223_000009_create_access_list_table;
|
||||
pub mod m20251223_000010_create_access_list_entry_table;
|
||||
pub mod m20251223_000011_create_proxy_host_access_list_table;
|
||||
pub mod m20251223_000012_create_stream_service_access_list_table;
|
||||
pub mod m20251230_000006_create_editing_session_table;
|
||||
|
||||
@@ -1,124 +0,0 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -1,100 +0,0 @@
|
||||
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,
|
||||
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::m20251223_000006_create_proxy_host_table::ProxyHost::Table,
|
||||
super::m20251223_000006_create_proxy_host_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::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
|
||||
}
|
||||
}
|
||||
@@ -1,112 +0,0 @@
|
||||
use sea_orm_migration::{prelude::*, schema::*};
|
||||
|
||||
#[derive(DeriveMigrationName)]
|
||||
pub struct Migration;
|
||||
|
||||
#[forbid(dead_code)]
|
||||
#[derive(DeriveIden)]
|
||||
pub enum StreamService {
|
||||
Table,
|
||||
Id,
|
||||
Name,
|
||||
ListenHost,
|
||||
ListenPort,
|
||||
Protocol,
|
||||
Mode,
|
||||
ForwardHost,
|
||||
ForwardPort,
|
||||
UpstreamId,
|
||||
PreservedClientIp,
|
||||
Enabled,
|
||||
Meta,
|
||||
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(StreamService::Table)
|
||||
.if_not_exists()
|
||||
.col(pk_uuid(StreamService::Id))
|
||||
.col(ColumnDef::new(StreamService::Name).string().null())
|
||||
.col(
|
||||
ColumnDef::new(StreamService::ListenHost)
|
||||
.string()
|
||||
.default("0.0.0.0")
|
||||
.not_null(),
|
||||
)
|
||||
.col(ColumnDef::new(StreamService::ListenPort).integer().not_null())
|
||||
.col(ColumnDef::new(StreamService::Protocol).string().not_null())
|
||||
.col(
|
||||
ColumnDef::new(StreamService::Mode)
|
||||
.string()
|
||||
.default("direct")
|
||||
.not_null(),
|
||||
)
|
||||
.col(ColumnDef::new(StreamService::ForwardHost).string().null())
|
||||
.col(ColumnDef::new(StreamService::ForwardPort).integer().null())
|
||||
.col(ColumnDef::new(StreamService::UpstreamId).uuid().null())
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fk-stream-service-upstream-id")
|
||||
.from(StreamService::Table, StreamService::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(StreamService::PreservedClientIp)
|
||||
.boolean()
|
||||
.default(false)
|
||||
.not_null(),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(StreamService::Enabled)
|
||||
.boolean()
|
||||
.default(true)
|
||||
.not_null(),
|
||||
)
|
||||
.col(ColumnDef::new(StreamService::Meta).json_binary().null())
|
||||
.col(ColumnDef::new(StreamService::CreatedBy).uuid().null())
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fk-stream-service-created-by")
|
||||
.from(StreamService::Table, StreamService::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(StreamService::CreatedAt)
|
||||
.timestamp()
|
||||
.default(SimpleExpr::Keyword(Keyword::CurrentTimestamp))
|
||||
.not_null(),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(StreamService::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(StreamService::Table).to_owned())
|
||||
.await
|
||||
}
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
use sea_orm_migration::{prelude::*, schema::*};
|
||||
|
||||
#[derive(DeriveMigrationName)]
|
||||
pub struct Migration;
|
||||
|
||||
#[forbid(dead_code)]
|
||||
#[derive(DeriveIden)]
|
||||
pub enum AccessList {
|
||||
Table,
|
||||
Id,
|
||||
Name,
|
||||
Description,
|
||||
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(AccessList::Table)
|
||||
.if_not_exists()
|
||||
.col(pk_uuid(AccessList::Id))
|
||||
.col(ColumnDef::new(AccessList::Name).string().not_null())
|
||||
.col(ColumnDef::new(AccessList::Description).text().null())
|
||||
.col(ColumnDef::new(AccessList::CreatedBy).uuid().null())
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fk-access-list-created-by")
|
||||
.from(AccessList::Table, AccessList::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(AccessList::CreatedAt)
|
||||
.timestamp()
|
||||
.default(SimpleExpr::Keyword(Keyword::CurrentTimestamp))
|
||||
.not_null(),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(AccessList::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(AccessList::Table).to_owned())
|
||||
.await
|
||||
}
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
use sea_orm_migration::{prelude::*, schema::*};
|
||||
|
||||
#[derive(DeriveMigrationName)]
|
||||
pub struct Migration;
|
||||
|
||||
#[forbid(dead_code)]
|
||||
#[derive(DeriveIden)]
|
||||
pub enum AccessListEntry {
|
||||
Table,
|
||||
Id,
|
||||
AccessListId,
|
||||
EntryType,
|
||||
Value,
|
||||
Comment,
|
||||
CreatedAt,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigrationTrait for Migration {
|
||||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(AccessListEntry::Table)
|
||||
.if_not_exists()
|
||||
.col(pk_uuid(AccessListEntry::Id))
|
||||
.col(ColumnDef::new(AccessListEntry::AccessListId).uuid().not_null())
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fk-access-list-entry-access-list-id")
|
||||
.from(AccessListEntry::Table, AccessListEntry::AccessListId)
|
||||
.to(
|
||||
super::m20251223_000009_create_access_list_table::AccessList::Table,
|
||||
super::m20251223_000009_create_access_list_table::AccessList::Id,
|
||||
)
|
||||
.on_delete(ForeignKeyAction::Cascade)
|
||||
.on_update(ForeignKeyAction::Cascade),
|
||||
)
|
||||
.col(ColumnDef::new(AccessListEntry::EntryType).string().not_null())
|
||||
.col(ColumnDef::new(AccessListEntry::Value).string().not_null())
|
||||
.col(ColumnDef::new(AccessListEntry::Comment).text().null())
|
||||
.col(
|
||||
ColumnDef::new(AccessListEntry::CreatedAt)
|
||||
.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(AccessListEntry::Table).to_owned())
|
||||
.await
|
||||
}
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
use sea_orm_migration::{prelude::*, schema::*};
|
||||
|
||||
#[derive(DeriveMigrationName)]
|
||||
pub struct Migration;
|
||||
|
||||
#[forbid(dead_code)]
|
||||
#[derive(DeriveIden)]
|
||||
pub enum ProxyHostAccessList {
|
||||
Table,
|
||||
Id,
|
||||
ProxyHostId,
|
||||
AccessListId,
|
||||
CreatedAt,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigrationTrait for Migration {
|
||||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(ProxyHostAccessList::Table)
|
||||
.if_not_exists()
|
||||
.col(pk_uuid(ProxyHostAccessList::Id))
|
||||
.col(ColumnDef::new(ProxyHostAccessList::ProxyHostId).uuid().not_null())
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fk-proxy-host-access-list-host-id")
|
||||
.from(ProxyHostAccessList::Table, ProxyHostAccessList::ProxyHostId)
|
||||
.to(
|
||||
super::m20251223_000006_create_proxy_host_table::ProxyHost::Table,
|
||||
super::m20251223_000006_create_proxy_host_table::ProxyHost::Id,
|
||||
)
|
||||
.on_delete(ForeignKeyAction::Cascade)
|
||||
.on_update(ForeignKeyAction::Cascade),
|
||||
)
|
||||
.col(ColumnDef::new(ProxyHostAccessList::AccessListId).uuid().not_null())
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fk-proxy-host-access-list-access-list-id")
|
||||
.from(ProxyHostAccessList::Table, ProxyHostAccessList::AccessListId)
|
||||
.to(
|
||||
super::m20251223_000009_create_access_list_table::AccessList::Table,
|
||||
super::m20251223_000009_create_access_list_table::AccessList::Id,
|
||||
)
|
||||
.on_delete(ForeignKeyAction::Cascade)
|
||||
.on_update(ForeignKeyAction::Cascade),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(ProxyHostAccessList::CreatedAt)
|
||||
.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(ProxyHostAccessList::Table).to_owned())
|
||||
.await
|
||||
}
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
use sea_orm_migration::{prelude::*, schema::*};
|
||||
|
||||
#[derive(DeriveMigrationName)]
|
||||
pub struct Migration;
|
||||
|
||||
#[forbid(dead_code)]
|
||||
#[derive(DeriveIden)]
|
||||
pub enum StreamServiceAccessList {
|
||||
Table,
|
||||
Id,
|
||||
StreamServiceId,
|
||||
AccessListId,
|
||||
CreatedAt,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigrationTrait for Migration {
|
||||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(StreamServiceAccessList::Table)
|
||||
.if_not_exists()
|
||||
.col(pk_uuid(StreamServiceAccessList::Id))
|
||||
.col(ColumnDef::new(StreamServiceAccessList::StreamServiceId).uuid().not_null())
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fk-stream-service-access-list-service-id")
|
||||
.from(StreamServiceAccessList::Table, StreamServiceAccessList::StreamServiceId)
|
||||
.to(
|
||||
super::m20251223_000008_create_stream_service_table::StreamService::Table,
|
||||
super::m20251223_000008_create_stream_service_table::StreamService::Id,
|
||||
)
|
||||
.on_delete(ForeignKeyAction::Cascade)
|
||||
.on_update(ForeignKeyAction::Cascade),
|
||||
)
|
||||
.col(ColumnDef::new(StreamServiceAccessList::AccessListId).uuid().not_null())
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fk-stream-service-access-list-access-list-id")
|
||||
.from(StreamServiceAccessList::Table, StreamServiceAccessList::AccessListId)
|
||||
.to(
|
||||
super::m20251223_000009_create_access_list_table::AccessList::Table,
|
||||
super::m20251223_000009_create_access_list_table::AccessList::Id,
|
||||
)
|
||||
.on_delete(ForeignKeyAction::Cascade)
|
||||
.on_update(ForeignKeyAction::Cascade),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(StreamServiceAccessList::CreatedAt)
|
||||
.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(StreamServiceAccessList::Table).to_owned())
|
||||
.await
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
use sea_orm_migration::{prelude::*, schema::*};
|
||||
|
||||
#[derive(DeriveMigrationName)]
|
||||
pub struct Migration;
|
||||
|
||||
#[forbid(dead_code)]
|
||||
#[derive(DeriveIden)]
|
||||
pub enum EditingSession {
|
||||
Table,
|
||||
Id,
|
||||
Name,
|
||||
CreatedBy,
|
||||
Status,
|
||||
CreatedAt,
|
||||
AppliedAt,
|
||||
AppliedBy,
|
||||
ExpiresAt,
|
||||
}
|
||||
|
||||
#[forbid(dead_code)]
|
||||
#[derive(DeriveIden)]
|
||||
pub enum EditOperation {
|
||||
Table,
|
||||
Id,
|
||||
SessionId,
|
||||
ResourceType,
|
||||
ResourceId,
|
||||
OperationType,
|
||||
Payload,
|
||||
CreatedAt,
|
||||
AppliedAt,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigrationTrait for Migration {
|
||||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(EditingSession::Table)
|
||||
.if_not_exists()
|
||||
.col(pk_uuid(EditingSession::Id))
|
||||
.col(ColumnDef::new(EditingSession::Name).string().null())
|
||||
.col(ColumnDef::new(EditingSession::CreatedBy).uuid().null())
|
||||
.col(
|
||||
ColumnDef::new(EditingSession::Status)
|
||||
.string()
|
||||
.default("pending")
|
||||
.not_null(),
|
||||
)
|
||||
.col(
|
||||
ColumnDef::new(EditingSession::CreatedAt)
|
||||
.timestamp()
|
||||
.default(SimpleExpr::Keyword(Keyword::CurrentTimestamp))
|
||||
.not_null(),
|
||||
)
|
||||
.col(ColumnDef::new(EditingSession::AppliedAt).timestamp().null())
|
||||
.col(ColumnDef::new(EditingSession::AppliedBy).uuid().null())
|
||||
.col(ColumnDef::new(EditingSession::ExpiresAt).timestamp().null())
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(EditOperation::Table)
|
||||
.if_not_exists()
|
||||
.col(pk_uuid(EditOperation::Id))
|
||||
.col(ColumnDef::new(EditOperation::SessionId).uuid().not_null())
|
||||
.col(
|
||||
ColumnDef::new(EditOperation::ResourceType)
|
||||
.string()
|
||||
.not_null(),
|
||||
) // e.g. "upstream", "location"
|
||||
.col(ColumnDef::new(EditOperation::ResourceId).uuid().null()) // null for create
|
||||
.col(
|
||||
ColumnDef::new(EditOperation::OperationType)
|
||||
.string()
|
||||
.not_null(),
|
||||
) // "create"|"update"|"delete"
|
||||
.col(
|
||||
ColumnDef::new(EditOperation::Payload)
|
||||
.json_binary()
|
||||
.not_null(),
|
||||
) // patch or full object
|
||||
.col(
|
||||
ColumnDef::new(EditOperation::CreatedAt)
|
||||
.timestamp()
|
||||
.default(SimpleExpr::Keyword(Keyword::CurrentTimestamp))
|
||||
.not_null(),
|
||||
)
|
||||
.col(ColumnDef::new(EditOperation::AppliedAt).timestamp().null())
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fk-edit-op-session")
|
||||
.from(EditOperation::Table, EditOperation::SessionId)
|
||||
.to(EditingSession::Table, EditingSession::Id)
|
||||
.on_delete(ForeignKeyAction::Cascade)
|
||||
.on_update(ForeignKeyAction::Cascade),
|
||||
)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.drop_table(Table::drop().table(EditOperation::Table).to_owned())
|
||||
.await?;
|
||||
manager
|
||||
.drop_table(Table::drop().table(EditingSession::Table).to_owned())
|
||||
.await
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user