From b43f9fcb0028c22b72e5341f831daa98cc257726 Mon Sep 17 00:00:00 2001 From: GW_MC <72297530+GWMCwing@users.noreply.github.com> Date: Tue, 30 Dec 2025 15:09:33 +0800 Subject: [PATCH] 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. --- .../src/generated/entities/access_list.rs | 34 ----- .../generated/entities/access_list_entry.rs | 28 ---- .../{audit_log.rs => edit_operation.rs} | 19 +-- .../src/generated/entities/editing_session.rs | 23 ++++ .../src/generated/entities/location.rs | 45 ------- public/database/src/generated/entities/mod.rs | 9 +- .../src/generated/entities/prelude.rs | 9 +- .../src/generated/entities/proxy_host.rs | 50 ------- .../entities/proxy_host_access_list.rs | 33 ----- .../src/generated/entities/session.rs | 29 ---- .../src/generated/entities/stream_service.rs | 47 ------- .../entities/stream_service_access_list.rs | 33 ----- .../src/generated/entities/upstream.rs | 6 - .../database/src/generated/entities/user.rs | 6 - public/migration/src/lib.rs | 8 +- public/migration/src/migrations.rs | 8 +- ...20251223_000006_create_proxy_host_table.rs | 124 ------------------ .../m20251223_000007_create_location_table.rs | 100 -------------- ...1223_000008_create_stream_service_table.rs | 112 ---------------- ...0251223_000009_create_access_list_table.rs | 63 --------- ...3_000010_create_access_list_entry_table.rs | 58 -------- ...011_create_proxy_host_access_list_table.rs | 65 --------- ...create_stream_service_access_list_table.rs | 65 --------- ...230_000006_create_editing_session_table.rs | 117 +++++++++++++++++ 24 files changed, 156 insertions(+), 935 deletions(-) delete mode 100644 public/database/src/generated/entities/access_list.rs delete mode 100644 public/database/src/generated/entities/access_list_entry.rs rename public/database/src/generated/entities/{audit_log.rs => edit_operation.rs} (59%) create mode 100644 public/database/src/generated/entities/editing_session.rs delete mode 100644 public/database/src/generated/entities/location.rs delete mode 100644 public/database/src/generated/entities/proxy_host.rs delete mode 100644 public/database/src/generated/entities/proxy_host_access_list.rs delete mode 100644 public/database/src/generated/entities/session.rs delete mode 100644 public/database/src/generated/entities/stream_service.rs delete mode 100644 public/database/src/generated/entities/stream_service_access_list.rs delete mode 100644 public/migration/src/migrations/m20251223_000006_create_proxy_host_table.rs delete mode 100644 public/migration/src/migrations/m20251223_000007_create_location_table.rs delete mode 100644 public/migration/src/migrations/m20251223_000008_create_stream_service_table.rs delete mode 100644 public/migration/src/migrations/m20251223_000009_create_access_list_table.rs delete mode 100644 public/migration/src/migrations/m20251223_000010_create_access_list_entry_table.rs delete mode 100644 public/migration/src/migrations/m20251223_000011_create_proxy_host_access_list_table.rs delete mode 100644 public/migration/src/migrations/m20251223_000012_create_stream_service_access_list_table.rs create mode 100644 public/migration/src/migrations/m20251230_000006_create_editing_session_table.rs diff --git a/public/database/src/generated/entities/access_list.rs b/public/database/src/generated/entities/access_list.rs deleted file mode 100644 index 93fd0e5..0000000 --- a/public/database/src/generated/entities/access_list.rs +++ /dev/null @@ -1,34 +0,0 @@ -//! `SeaORM` Entity, @generated by sea-orm-codegen 2.0.0-rc.18 - -use sea_orm::entity::prelude::*; -use serde::{Deserialize, Serialize}; - -#[sea_orm::model] -#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel, Serialize, Deserialize)] -#[sea_orm(table_name = "access_list")] -pub struct Model { - #[sea_orm(primary_key, auto_increment = false)] - pub id: Uuid, - pub name: String, - #[sea_orm(column_type = "Text", nullable)] - pub description: Option, - pub created_by: Option, - pub created_at: DateTimeUtc, - pub updated_at: DateTimeUtc, - #[sea_orm(has_many)] - pub access_list_entries: HasMany, - #[sea_orm(has_many)] - pub proxy_host_access_lists: HasMany, - #[sea_orm(has_many)] - pub stream_service_access_lists: HasMany, - #[sea_orm( - belongs_to, - from = "created_by", - to = "id", - on_update = "Cascade", - on_delete = "SetNull" - )] - pub user: HasOne, -} - -impl ActiveModelBehavior for ActiveModel {} diff --git a/public/database/src/generated/entities/access_list_entry.rs b/public/database/src/generated/entities/access_list_entry.rs deleted file mode 100644 index 403ae92..0000000 --- a/public/database/src/generated/entities/access_list_entry.rs +++ /dev/null @@ -1,28 +0,0 @@ -//! `SeaORM` Entity, @generated by sea-orm-codegen 2.0.0-rc.18 - -use sea_orm::entity::prelude::*; -use serde::{Deserialize, Serialize}; - -#[sea_orm::model] -#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel, Serialize, Deserialize)] -#[sea_orm(table_name = "access_list_entry")] -pub struct Model { - #[sea_orm(primary_key, auto_increment = false)] - pub id: Uuid, - pub access_list_id: Uuid, - pub entry_type: String, - pub value: String, - #[sea_orm(column_type = "Text", nullable)] - pub comment: Option, - pub created_at: DateTimeUtc, - #[sea_orm( - belongs_to, - from = "access_list_id", - to = "id", - on_update = "Cascade", - on_delete = "Cascade" - )] - pub access_list: HasOne, -} - -impl ActiveModelBehavior for ActiveModel {} diff --git a/public/database/src/generated/entities/audit_log.rs b/public/database/src/generated/entities/edit_operation.rs similarity index 59% rename from public/database/src/generated/entities/audit_log.rs rename to public/database/src/generated/entities/edit_operation.rs index 960aee7..98b4275 100644 --- a/public/database/src/generated/entities/audit_log.rs +++ b/public/database/src/generated/entities/edit_operation.rs @@ -5,25 +5,26 @@ use serde::{Deserialize, Serialize}; #[sea_orm::model] #[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel, Serialize, Deserialize)] -#[sea_orm(table_name = "audit_log")] +#[sea_orm(table_name = "edit_operation")] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: Uuid, - pub actor_id: Option, - pub action: String, + pub session_id: Uuid, pub resource_type: String, - pub resource_id: String, - #[sea_orm(column_type = "JsonBinary", nullable)] - pub details: Option, + pub resource_id: Option, + pub operation_type: String, + #[sea_orm(column_type = "JsonBinary")] + pub payload: Json, pub created_at: DateTimeUtc, + pub applied_at: Option, #[sea_orm( belongs_to, - from = "actor_id", + from = "session_id", to = "id", on_update = "Cascade", - on_delete = "SetNull" + on_delete = "Cascade" )] - pub user: HasOne, + pub editing_session: HasOne, } impl ActiveModelBehavior for ActiveModel {} diff --git a/public/database/src/generated/entities/editing_session.rs b/public/database/src/generated/entities/editing_session.rs new file mode 100644 index 0000000..595305d --- /dev/null +++ b/public/database/src/generated/entities/editing_session.rs @@ -0,0 +1,23 @@ +//! `SeaORM` Entity, @generated by sea-orm-codegen 2.0.0-rc.18 + +use sea_orm::entity::prelude::*; +use serde::{Deserialize, Serialize}; + +#[sea_orm::model] +#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel, Serialize, Deserialize)] +#[sea_orm(table_name = "editing_session")] +pub struct Model { + #[sea_orm(primary_key, auto_increment = false)] + pub id: Uuid, + pub name: Option, + pub created_by: Option, + pub status: String, + pub created_at: DateTimeUtc, + pub applied_at: Option, + pub applied_by: Option, + pub expires_at: Option, + #[sea_orm(has_many)] + pub edit_operations: HasMany, +} + +impl ActiveModelBehavior for ActiveModel {} diff --git a/public/database/src/generated/entities/location.rs b/public/database/src/generated/entities/location.rs deleted file mode 100644 index 99f1c32..0000000 --- a/public/database/src/generated/entities/location.rs +++ /dev/null @@ -1,45 +0,0 @@ -//! `SeaORM` Entity, @generated by sea-orm-codegen 2.0.0-rc.18 - -use sea_orm::entity::prelude::*; -use serde::{Deserialize, Serialize}; - -#[sea_orm::model] -#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel, Serialize, Deserialize)] -#[sea_orm(table_name = "location")] -pub struct Model { - #[sea_orm(primary_key, auto_increment = false)] - pub id: Uuid, - pub host_id: Uuid, - pub path: String, - pub match_type: String, - pub order: i64, - pub upstream_id: Option, - pub proxy_pass_host: Option, - pub proxy_pass_port: Option, - pub preserve_host_header: Option, - #[sea_orm(column_type = "JsonBinary", nullable)] - pub allowed_methods: Option, - #[sea_orm(column_type = "Text", nullable)] - pub custom_config: Option, - pub enabled: bool, - pub created_at: DateTimeUtc, - pub updated_at: DateTimeUtc, - #[sea_orm( - belongs_to, - from = "host_id", - to = "id", - on_update = "Cascade", - on_delete = "Cascade" - )] - pub proxy_host: HasOne, - #[sea_orm( - belongs_to, - from = "upstream_id", - to = "id", - on_update = "Cascade", - on_delete = "SetNull" - )] - pub upstream: HasOne, -} - -impl ActiveModelBehavior for ActiveModel {} diff --git a/public/database/src/generated/entities/mod.rs b/public/database/src/generated/entities/mod.rs index 33598a4..1f4ed58 100644 --- a/public/database/src/generated/entities/mod.rs +++ b/public/database/src/generated/entities/mod.rs @@ -2,14 +2,9 @@ pub mod prelude; -pub mod access_list; -pub mod access_list_entry; pub mod config; -pub mod location; -pub mod proxy_host; -pub mod proxy_host_access_list; -pub mod stream_service; -pub mod stream_service_access_list; +pub mod edit_operation; +pub mod editing_session; pub mod upstream; pub mod upstream_target; pub mod user; diff --git a/public/database/src/generated/entities/prelude.rs b/public/database/src/generated/entities/prelude.rs index d09f1c3..a66a6d5 100644 --- a/public/database/src/generated/entities/prelude.rs +++ b/public/database/src/generated/entities/prelude.rs @@ -1,13 +1,8 @@ //! `SeaORM` Entity, @generated by sea-orm-codegen 2.0.0-rc.18 -pub use super::access_list::Entity as AccessList; -pub use super::access_list_entry::Entity as AccessListEntry; pub use super::config::Entity as Config; -pub use super::location::Entity as Location; -pub use super::proxy_host::Entity as ProxyHost; -pub use super::proxy_host_access_list::Entity as ProxyHostAccessList; -pub use super::stream_service::Entity as StreamService; -pub use super::stream_service_access_list::Entity as StreamServiceAccessList; +pub use super::edit_operation::Entity as EditOperation; +pub use super::editing_session::Entity as EditingSession; pub use super::upstream::Entity as Upstream; pub use super::upstream_target::Entity as UpstreamTarget; pub use super::user::Entity as User; diff --git a/public/database/src/generated/entities/proxy_host.rs b/public/database/src/generated/entities/proxy_host.rs deleted file mode 100644 index b521b02..0000000 --- a/public/database/src/generated/entities/proxy_host.rs +++ /dev/null @@ -1,50 +0,0 @@ -//! `SeaORM` Entity, @generated by sea-orm-codegen 2.0.0-rc.18 - -use sea_orm::entity::prelude::*; -use serde::{Deserialize, Serialize}; - -#[sea_orm::model] -#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel, Serialize, Deserialize)] -#[sea_orm(table_name = "proxy_host")] -pub struct Model { - #[sea_orm(primary_key, auto_increment = false)] - pub id: Uuid, - pub name: Option, - pub domain: String, - pub scheme: String, - pub listen_port: i64, - pub forward_scheme: String, - pub forward_host: Option, - pub forward_port: Option, - pub preserve_host_header: bool, - pub enable_websocket: bool, - pub enabled: bool, - #[sea_orm(column_type = "JsonBinary", nullable)] - pub meta: Option, - pub default_upstream_id: Option, - pub created_by: Option, - pub created_at: DateTimeUtc, - pub updated_at: DateTimeUtc, - #[sea_orm(has_many)] - pub locations: HasMany, - #[sea_orm(has_many)] - pub proxy_host_access_lists: HasMany, - #[sea_orm( - belongs_to, - from = "default_upstream_id", - to = "id", - on_update = "Cascade", - on_delete = "SetNull" - )] - pub upstream: HasOne, - #[sea_orm( - belongs_to, - from = "created_by", - to = "id", - on_update = "Cascade", - on_delete = "SetNull" - )] - pub user: HasOne, -} - -impl ActiveModelBehavior for ActiveModel {} diff --git a/public/database/src/generated/entities/proxy_host_access_list.rs b/public/database/src/generated/entities/proxy_host_access_list.rs deleted file mode 100644 index 0818588..0000000 --- a/public/database/src/generated/entities/proxy_host_access_list.rs +++ /dev/null @@ -1,33 +0,0 @@ -//! `SeaORM` Entity, @generated by sea-orm-codegen 2.0.0-rc.18 - -use sea_orm::entity::prelude::*; -use serde::{Deserialize, Serialize}; - -#[sea_orm::model] -#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel, Serialize, Deserialize)] -#[sea_orm(table_name = "proxy_host_access_list")] -pub struct Model { - #[sea_orm(primary_key, auto_increment = false)] - pub id: Uuid, - pub proxy_host_id: Uuid, - pub access_list_id: Uuid, - pub created_at: DateTimeUtc, - #[sea_orm( - belongs_to, - from = "access_list_id", - to = "id", - on_update = "Cascade", - on_delete = "Cascade" - )] - pub access_list: HasOne, - #[sea_orm( - belongs_to, - from = "proxy_host_id", - to = "id", - on_update = "Cascade", - on_delete = "Cascade" - )] - pub proxy_host: HasOne, -} - -impl ActiveModelBehavior for ActiveModel {} diff --git a/public/database/src/generated/entities/session.rs b/public/database/src/generated/entities/session.rs deleted file mode 100644 index fc26f9f..0000000 --- a/public/database/src/generated/entities/session.rs +++ /dev/null @@ -1,29 +0,0 @@ -//! `SeaORM` Entity, @generated by sea-orm-codegen 2.0.0-rc.18 - -use sea_orm::entity::prelude::*; -use serde::{Deserialize, Serialize}; - -#[sea_orm::model] -#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel, Serialize, Deserialize)] -#[sea_orm(table_name = "session")] -pub struct Model { - #[sea_orm(primary_key, auto_increment = false)] - pub id: Uuid, - pub user_id: Uuid, - #[sea_orm(unique)] - pub refresh_token_hash: Option, - pub expires_at: DateTimeUtc, - pub revoked_at: Option, - pub created_at: DateTimeUtc, - pub updated_at: DateTimeUtc, - #[sea_orm( - belongs_to, - from = "user_id", - to = "id", - on_update = "Cascade", - on_delete = "Cascade" - )] - pub user: HasOne, -} - -impl ActiveModelBehavior for ActiveModel {} diff --git a/public/database/src/generated/entities/stream_service.rs b/public/database/src/generated/entities/stream_service.rs deleted file mode 100644 index 08a92fe..0000000 --- a/public/database/src/generated/entities/stream_service.rs +++ /dev/null @@ -1,47 +0,0 @@ -//! `SeaORM` Entity, @generated by sea-orm-codegen 2.0.0-rc.18 - -use sea_orm::entity::prelude::*; -use serde::{Deserialize, Serialize}; - -#[sea_orm::model] -#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel, Serialize, Deserialize)] -#[sea_orm(table_name = "stream_service")] -pub struct Model { - #[sea_orm(primary_key, auto_increment = false)] - pub id: Uuid, - pub name: Option, - pub listen_host: String, - pub listen_port: i64, - pub protocol: String, - pub mode: String, - pub forward_host: Option, - pub forward_port: Option, - pub upstream_id: Option, - pub preserved_client_ip: bool, - pub enabled: bool, - #[sea_orm(column_type = "JsonBinary", nullable)] - pub meta: Option, - pub created_by: Option, - pub created_at: DateTimeUtc, - pub updated_at: DateTimeUtc, - #[sea_orm(has_many)] - pub stream_service_access_lists: HasMany, - #[sea_orm( - belongs_to, - from = "upstream_id", - to = "id", - on_update = "Cascade", - on_delete = "SetNull" - )] - pub upstream: HasOne, - #[sea_orm( - belongs_to, - from = "created_by", - to = "id", - on_update = "Cascade", - on_delete = "SetNull" - )] - pub user: HasOne, -} - -impl ActiveModelBehavior for ActiveModel {} diff --git a/public/database/src/generated/entities/stream_service_access_list.rs b/public/database/src/generated/entities/stream_service_access_list.rs deleted file mode 100644 index 9ec8043..0000000 --- a/public/database/src/generated/entities/stream_service_access_list.rs +++ /dev/null @@ -1,33 +0,0 @@ -//! `SeaORM` Entity, @generated by sea-orm-codegen 2.0.0-rc.18 - -use sea_orm::entity::prelude::*; -use serde::{Deserialize, Serialize}; - -#[sea_orm::model] -#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel, Serialize, Deserialize)] -#[sea_orm(table_name = "stream_service_access_list")] -pub struct Model { - #[sea_orm(primary_key, auto_increment = false)] - pub id: Uuid, - pub stream_service_id: Uuid, - pub access_list_id: Uuid, - pub created_at: DateTimeUtc, - #[sea_orm( - belongs_to, - from = "access_list_id", - to = "id", - on_update = "Cascade", - on_delete = "Cascade" - )] - pub access_list: HasOne, - #[sea_orm( - belongs_to, - from = "stream_service_id", - to = "id", - on_update = "Cascade", - on_delete = "Cascade" - )] - pub stream_service: HasOne, -} - -impl ActiveModelBehavior for ActiveModel {} diff --git a/public/database/src/generated/entities/upstream.rs b/public/database/src/generated/entities/upstream.rs index 3490112..bbbe5de 100644 --- a/public/database/src/generated/entities/upstream.rs +++ b/public/database/src/generated/entities/upstream.rs @@ -17,12 +17,6 @@ pub struct Model { pub created_at: DateTimeUtc, pub updated_at: DateTimeUtc, #[sea_orm(has_many)] - pub locations: HasMany, - #[sea_orm(has_many)] - pub proxy_hosts: HasMany, - #[sea_orm(has_many)] - pub stream_services: HasMany, - #[sea_orm(has_many)] pub upstream_targets: HasMany, } diff --git a/public/database/src/generated/entities/user.rs b/public/database/src/generated/entities/user.rs index 6e043f4..ab2edb2 100644 --- a/public/database/src/generated/entities/user.rs +++ b/public/database/src/generated/entities/user.rs @@ -18,12 +18,6 @@ pub struct Model { pub last_login_at: Option, pub deleted_at: Option, #[sea_orm(has_many)] - pub access_lists: HasMany, - #[sea_orm(has_many)] - pub proxy_hosts: HasMany, - #[sea_orm(has_many)] - pub stream_services: HasMany, - #[sea_orm(has_many)] pub user_identities: HasMany, } diff --git a/public/migration/src/lib.rs b/public/migration/src/lib.rs index 920a97d..71c86cc 100644 --- a/public/migration/src/lib.rs +++ b/public/migration/src/lib.rs @@ -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), ] } } diff --git a/public/migration/src/migrations.rs b/public/migration/src/migrations.rs index 1501f2a..55f0835 100644 --- a/public/migration/src/migrations.rs +++ b/public/migration/src/migrations.rs @@ -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; diff --git a/public/migration/src/migrations/m20251223_000006_create_proxy_host_table.rs b/public/migration/src/migrations/m20251223_000006_create_proxy_host_table.rs deleted file mode 100644 index bcdd3fa..0000000 --- a/public/migration/src/migrations/m20251223_000006_create_proxy_host_table.rs +++ /dev/null @@ -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 - } -} diff --git a/public/migration/src/migrations/m20251223_000007_create_location_table.rs b/public/migration/src/migrations/m20251223_000007_create_location_table.rs deleted file mode 100644 index 5da97d4..0000000 --- a/public/migration/src/migrations/m20251223_000007_create_location_table.rs +++ /dev/null @@ -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 - } -} diff --git a/public/migration/src/migrations/m20251223_000008_create_stream_service_table.rs b/public/migration/src/migrations/m20251223_000008_create_stream_service_table.rs deleted file mode 100644 index e99ae60..0000000 --- a/public/migration/src/migrations/m20251223_000008_create_stream_service_table.rs +++ /dev/null @@ -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 - } -} diff --git a/public/migration/src/migrations/m20251223_000009_create_access_list_table.rs b/public/migration/src/migrations/m20251223_000009_create_access_list_table.rs deleted file mode 100644 index 7d947b7..0000000 --- a/public/migration/src/migrations/m20251223_000009_create_access_list_table.rs +++ /dev/null @@ -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 - } -} diff --git a/public/migration/src/migrations/m20251223_000010_create_access_list_entry_table.rs b/public/migration/src/migrations/m20251223_000010_create_access_list_entry_table.rs deleted file mode 100644 index 2dea34e..0000000 --- a/public/migration/src/migrations/m20251223_000010_create_access_list_entry_table.rs +++ /dev/null @@ -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 - } -} diff --git a/public/migration/src/migrations/m20251223_000011_create_proxy_host_access_list_table.rs b/public/migration/src/migrations/m20251223_000011_create_proxy_host_access_list_table.rs deleted file mode 100644 index 27f085e..0000000 --- a/public/migration/src/migrations/m20251223_000011_create_proxy_host_access_list_table.rs +++ /dev/null @@ -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 - } -} diff --git a/public/migration/src/migrations/m20251223_000012_create_stream_service_access_list_table.rs b/public/migration/src/migrations/m20251223_000012_create_stream_service_access_list_table.rs deleted file mode 100644 index 84d8b41..0000000 --- a/public/migration/src/migrations/m20251223_000012_create_stream_service_access_list_table.rs +++ /dev/null @@ -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 - } -} diff --git a/public/migration/src/migrations/m20251230_000006_create_editing_session_table.rs b/public/migration/src/migrations/m20251230_000006_create_editing_session_table.rs new file mode 100644 index 0000000..2765fa3 --- /dev/null +++ b/public/migration/src/migrations/m20251230_000006_create_editing_session_table.rs @@ -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 + } +}