feature/upstream-service #13
@@ -1,30 +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 = "edit_operation")]
|
|
||||||
pub struct Model {
|
|
||||||
#[sea_orm(primary_key, auto_increment = false)]
|
|
||||||
pub id: Uuid,
|
|
||||||
pub session_id: Uuid,
|
|
||||||
pub resource_type: String,
|
|
||||||
pub resource_id: Option<Uuid>,
|
|
||||||
pub operation_type: String,
|
|
||||||
#[sea_orm(column_type = "JsonBinary")]
|
|
||||||
pub payload: Json,
|
|
||||||
pub created_at: DateTimeUtc,
|
|
||||||
pub applied_at: Option<DateTimeUtc>,
|
|
||||||
#[sea_orm(
|
|
||||||
belongs_to,
|
|
||||||
from = "session_id",
|
|
||||||
to = "id",
|
|
||||||
on_update = "Cascade",
|
|
||||||
on_delete = "Cascade"
|
|
||||||
)]
|
|
||||||
pub editing_session: HasOne<super::editing_session::Entity>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ActiveModelBehavior for ActiveModel {}
|
|
||||||
@@ -1,23 +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 = "editing_session")]
|
|
||||||
pub struct Model {
|
|
||||||
#[sea_orm(primary_key, auto_increment = false)]
|
|
||||||
pub id: Uuid,
|
|
||||||
pub name: Option<String>,
|
|
||||||
pub created_by: Option<Uuid>,
|
|
||||||
pub status: String,
|
|
||||||
pub created_at: DateTimeUtc,
|
|
||||||
pub applied_at: Option<DateTimeUtc>,
|
|
||||||
pub applied_by: Option<Uuid>,
|
|
||||||
pub expires_at: Option<DateTimeUtc>,
|
|
||||||
#[sea_orm(has_many)]
|
|
||||||
pub edit_operations: HasMany<super::edit_operation::Entity>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ActiveModelBehavior for ActiveModel {}
|
|
||||||
@@ -3,8 +3,6 @@
|
|||||||
pub mod prelude;
|
pub mod prelude;
|
||||||
|
|
||||||
pub mod config;
|
pub mod config;
|
||||||
pub mod edit_operation;
|
|
||||||
pub mod editing_session;
|
|
||||||
pub mod upstream;
|
pub mod upstream;
|
||||||
pub mod upstream_target;
|
pub mod upstream_target;
|
||||||
pub mod user;
|
pub mod user;
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
//! `SeaORM` Entity, @generated by sea-orm-codegen 2.0.0-rc.18
|
//! `SeaORM` Entity, @generated by sea-orm-codegen 2.0.0-rc.18
|
||||||
|
|
||||||
pub use super::config::Entity as Config;
|
pub use super::config::Entity as Config;
|
||||||
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::Entity as Upstream;
|
||||||
pub use super::upstream_target::Entity as UpstreamTarget;
|
pub use super::upstream_target::Entity as UpstreamTarget;
|
||||||
pub use super::user::Entity as User;
|
pub use super::user::Entity as User;
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ impl MigratorTrait for Migrator {
|
|||||||
Box::new(m20251011_000003_create_user_identity_table::Migration),
|
Box::new(m20251011_000003_create_user_identity_table::Migration),
|
||||||
Box::new(m20251223_000004_create_upstream_table::Migration),
|
Box::new(m20251223_000004_create_upstream_table::Migration),
|
||||||
Box::new(m20251223_000005_create_upstream_target_table::Migration),
|
Box::new(m20251223_000005_create_upstream_target_table::Migration),
|
||||||
Box::new(m20251230_000006_create_editing_session_table::Migration),
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,4 +3,3 @@ pub mod m20251011_000002_create_user_table;
|
|||||||
pub mod m20251011_000003_create_user_identity_table;
|
pub mod m20251011_000003_create_user_identity_table;
|
||||||
pub mod m20251223_000004_create_upstream_table;
|
pub mod m20251223_000004_create_upstream_table;
|
||||||
pub mod m20251223_000005_create_upstream_target_table;
|
pub mod m20251223_000005_create_upstream_target_table;
|
||||||
pub mod m20251230_000006_create_editing_session_table;
|
|
||||||
|
|||||||
@@ -1,117 +0,0 @@
|
|||||||
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