1use super::project;
2use crate::db::{ChannelId, DevServerId, RemoteProjectId};
3use rpc::proto;
4use sea_orm::entity::prelude::*;
5
6#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
7#[sea_orm(table_name = "remote_projects")]
8pub struct Model {
9 #[sea_orm(primary_key)]
10 pub id: RemoteProjectId,
11 pub channel_id: ChannelId,
12 pub dev_server_id: DevServerId,
13 pub name: String,
14 pub path: String,
15}
16
17impl ActiveModelBehavior for ActiveModel {}
18
19#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
20pub enum Relation {
21 #[sea_orm(has_one = "super::project::Entity")]
22 Project,
23}
24
25impl Related<super::project::Entity> for Entity {
26 fn to() -> RelationDef {
27 Relation::Project.def()
28 }
29}
30
31impl Model {
32 pub fn to_proto(&self, project: Option<project::Model>) -> proto::RemoteProject {
33 proto::RemoteProject {
34 id: self.id.to_proto(),
35 project_id: project.map(|p| p.id.to_proto()),
36 channel_id: self.channel_id.to_proto(),
37 dev_server_id: self.dev_server_id.to_proto(),
38 name: self.name.clone(),
39 path: self.path.clone(),
40 }
41 }
42}