project_collaborator.rs

 1use crate::db::{ProjectCollaboratorId, ProjectId, ReplicaId, ServerId, UserId};
 2use rpc::ConnectionId;
 3use sea_orm::entity::prelude::*;
 4
 5#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
 6#[sea_orm(table_name = "project_collaborators")]
 7pub struct Model {
 8    #[sea_orm(primary_key)]
 9    pub id: ProjectCollaboratorId,
10    pub project_id: ProjectId,
11    pub connection_id: i32,
12    pub connection_server_id: ServerId,
13    pub user_id: UserId,
14    pub replica_id: ReplicaId,
15    pub is_host: bool,
16    pub committer_name: Option<String>,
17    pub committer_email: Option<String>,
18}
19
20impl Model {
21    pub const fn connection(&self) -> ConnectionId {
22        ConnectionId {
23            owner_id: self.connection_server_id.0 as u32,
24            id: self.connection_id as u32,
25        }
26    }
27}
28
29#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
30pub enum Relation {
31    #[sea_orm(
32        belongs_to = "super::project::Entity",
33        from = "Column::ProjectId",
34        to = "super::project::Column::Id"
35    )]
36    Project,
37}
38
39impl Related<super::project::Entity> for Entity {
40    fn to() -> RelationDef {
41        Relation::Project.def()
42    }
43}
44
45impl ActiveModelBehavior for ActiveModel {}