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}
17
18impl Model {
19    pub fn connection(&self) -> ConnectionId {
20        ConnectionId {
21            owner_id: self.connection_server_id.0 as u32,
22            id: self.connection_id as u32,
23        }
24    }
25}
26
27#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
28pub enum Relation {
29    #[sea_orm(
30        belongs_to = "super::project::Entity",
31        from = "Column::ProjectId",
32        to = "super::project::Column::Id"
33    )]
34    Project,
35}
36
37impl Related<super::project::Entity> for Entity {
38    fn to() -> RelationDef {
39        Relation::Project.def()
40    }
41}
42
43impl ActiveModelBehavior for ActiveModel {}