1use crate::llm::db::{ModelId, UsageId, UsageMeasureId};
2use sea_orm::entity::prelude::*;
3
4/// An LLM usage record.
5#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
6#[sea_orm(table_name = "usages")]
7pub struct Model {
8 #[sea_orm(primary_key)]
9 pub id: UsageId,
10 /// The ID of the Zed user.
11 ///
12 /// Corresponds to the `users` table in the primary collab database.
13 pub user_id: i32,
14 pub model_id: ModelId,
15 pub measure_id: UsageMeasureId,
16 pub timestamp: DateTime,
17 pub buckets: Vec<i64>,
18}
19
20#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
21pub enum Relation {
22 #[sea_orm(
23 belongs_to = "super::model::Entity",
24 from = "Column::ModelId",
25 to = "super::model::Column::Id"
26 )]
27 Model,
28 #[sea_orm(
29 belongs_to = "super::usage_measure::Entity",
30 from = "Column::MeasureId",
31 to = "super::usage_measure::Column::Id"
32 )]
33 UsageMeasure,
34}
35
36impl Related<super::model::Entity> for Entity {
37 fn to() -> RelationDef {
38 Relation::Model.def()
39 }
40}
41
42impl Related<super::usage_measure::Entity> for Entity {
43 fn to() -> RelationDef {
44 Relation::UsageMeasure.def()
45 }
46}
47
48impl ActiveModelBehavior for ActiveModel {}