microsandbox_db/entity/sandbox_label.rs
1//! Entity definition for the `sandbox_labels` table.
2
3use sea_orm::entity::prelude::*;
4
5//--------------------------------------------------------------------------------------------------
6// Types
7//--------------------------------------------------------------------------------------------------
8
9/// A user-defined label attached to a sandbox for metrics attribution. Keyed on
10/// `(sandbox_id, key)` so each key has at most one value per sandbox.
11#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
12#[sea_orm(table_name = "sandbox_labels")]
13pub struct Model {
14 #[sea_orm(primary_key, auto_increment = false)]
15 pub sandbox_id: i32,
16 #[sea_orm(primary_key, auto_increment = false)]
17 pub key: String,
18 pub value: String,
19}
20
21//--------------------------------------------------------------------------------------------------
22// Types: Relations
23//--------------------------------------------------------------------------------------------------
24
25/// Relations for the sandbox_label entity.
26#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
27pub enum Relation {
28 /// A label belongs to a sandbox.
29 #[sea_orm(
30 belongs_to = "super::sandbox::Entity",
31 from = "Column::SandboxId",
32 to = "super::sandbox::Column::Id",
33 on_delete = "Cascade"
34 )]
35 Sandbox,
36}
37
38impl Related<super::sandbox::Entity> for Entity {
39 fn to() -> RelationDef {
40 Relation::Sandbox.def()
41 }
42}
43
44//--------------------------------------------------------------------------------------------------
45// Trait Implementations
46//--------------------------------------------------------------------------------------------------
47
48impl ActiveModelBehavior for ActiveModel {}