From c749141da9552563c87dbc90744f00fe4e143b47 Mon Sep 17 00:00:00 2001 From: Meng Zhang Date: Thu, 5 Dec 2024 18:50:55 +0800 Subject: [PATCH] update --- .../0039_add-notification-inbox.up.sql | 2 +- ee/tabby-db/schema.sqlite | Bin 221184 -> 221184 bytes ee/tabby-db/schema/schema.sql | 2 +- ee/tabby-db/schema/schema.svg | 2 +- ee/tabby-db/src/notifications.rs | 18 +++++++++--------- ee/tabby-schema/src/dao.rs | 12 ++++++------ ee/tabby-schema/src/schema/notification.rs | 2 +- 7 files changed, 19 insertions(+), 19 deletions(-) diff --git a/ee/tabby-db/migrations/0039_add-notification-inbox.up.sql b/ee/tabby-db/migrations/0039_add-notification-inbox.up.sql index 765bb9a83738..04ca59cef9b7 100644 --- a/ee/tabby-db/migrations/0039_add-notification-inbox.up.sql +++ b/ee/tabby-db/migrations/0039_add-notification-inbox.up.sql @@ -5,7 +5,7 @@ CREATE TABLE notifications ( updated_at TIMESTAMP NOT NULL DEFAULT(DATETIME('now')), -- enum of admin, all_user - kind VARCHAR(255) NOT NULL DEFAULT 'admin', + recipient VARCHAR(255) NOT NULL DEFAULT 'admin', -- content of notification, in markdown format. content TEXT NOT NULL diff --git a/ee/tabby-db/schema.sqlite b/ee/tabby-db/schema.sqlite index 2a57ba44e0d9e0087e59909bc35d5bd75cbd6710..349a5d2b1b1148b46232f67bb0a2348fb7af88f9 100644 GIT binary patch delta 229 zcmZoTz}s+ucY?H_7y|=?84$xj&O{w!MzM_v!h#m223E!fEg^v+N8=_*A9?InwMz1K zgNg9w1o^}!ZNBA;zh8U1mFGv1!p9Zz&wfNM5Uad-av2w|*Xrigg6*pX8G)E-`)Wbv z1ir=G1_G=gON=)Q8ocKhXW-?y#K6v$#K60XH~1wj_?u&4~&=Y}3=-n9Ui@ zw$BGrOu{BWO&lPnHM2Xji>s?Mw)#$g>A@^NeV!XL-*hog=4+fqsmYlInW=dtlP@xg TO^*v^V;dS^qZP#-Map z$2+b~1~(`Z-oM3Zu!zR7nlrcPkqpFD@%XioEL!S>aHj6lq^eYGHS z0w1HvW2bk~T-yb_m_M*Ga&2Zb_|Fdjy7f+Z diff --git a/ee/tabby-db/schema/schema.sql b/ee/tabby-db/schema/schema.sql index 9807a6b81468..ef1e248389cc 100644 --- a/ee/tabby-db/schema/schema.sql +++ b/ee/tabby-db/schema/schema.sql @@ -228,7 +228,7 @@ CREATE TABLE notifications( created_at TIMESTAMP NOT NULL DEFAULT(DATETIME('now')), updated_at TIMESTAMP NOT NULL DEFAULT(DATETIME('now')), -- enum of admin, all_user - kind VARCHAR(255) NOT NULL DEFAULT 'admin', + recipient VARCHAR(255) NOT NULL DEFAULT 'admin', -- content of notification, in markdown format. content TEXT NOT NULL ); diff --git a/ee/tabby-db/schema/schema.svg b/ee/tabby-db/schema/schema.svg index 89358e7b451c..5596f9955dd9 100644 --- a/ee/tabby-db/schema/schema.svg +++ b/ee/tabby-db/schema/schema.svg @@ -211,7 +211,7 @@   -kind +recipient   diff --git a/ee/tabby-db/src/notifications.rs b/ee/tabby-db/src/notifications.rs index 9aa23aaf7a2b..520778c161a7 100644 --- a/ee/tabby-db/src/notifications.rs +++ b/ee/tabby-db/src/notifications.rs @@ -8,17 +8,17 @@ use crate::DbConn; pub struct NotificationDAO { pub id: i64, - pub kind: String, + pub recipient: String, pub content: String, pub created_at: DateTime, pub updated_at: DateTime, } impl DbConn { - pub async fn create_notification(&self, kind: &str, content: &str) -> Result { + pub async fn create_notification(&self, recipient: &str, content: &str) -> Result { let res = query!( - "INSERT INTO notifications (kind, content) VALUES (?, ?)", - kind, + "INSERT INTO notifications (recipient, content) VALUES (?, ?)", + recipient, content ) .execute(&self.pool) @@ -47,17 +47,17 @@ impl DbConn { .get_user(user_id) .await? .context("User doesn't exist")?; - let kind_clause = if user.is_admin { - "kind = 'all_user' OR kind = 'admin'" + let recipient_clause = if user.is_admin { + "recipient = 'all_user' OR recipient = 'admin'" } else { - "kind = 'all_user'" + "recipient = 'all_user'" }; let date_7days_ago = Utc::now() - Duration::days(7); let sql = format!( r#" - SELECT notifications.id, notifications.created_at, notifications.updated_at, kind, content + SELECT notifications.id, notifications.created_at, notifications.updated_at, recipient, content FROM notifications LEFT JOIN readed_notifications ON notifications.id = readed_notifications.notification_id - WHERE ({kind_clause}) AND notifications.created_at > '{date_7days_ago}' AND readed_notifications.user_id IS NULL -- notification is not marked as readed + WHERE ({recipient_clause}) AND notifications.created_at > '{date_7days_ago}' AND readed_notifications.user_id IS NULL -- notification is not marked as readed "# ); let notifications = query_as(&sql).fetch_all(&self.pool).await?; diff --git a/ee/tabby-schema/src/dao.rs b/ee/tabby-schema/src/dao.rs index 3a0ecc9f6773..a89f1df9f943 100644 --- a/ee/tabby-schema/src/dao.rs +++ b/ee/tabby-schema/src/dao.rs @@ -11,7 +11,7 @@ use tabby_db::{ use crate::{ integration::{Integration, IntegrationKind, IntegrationStatus}, interface::UserValue, - notification::NotificationKind, + notification::NotificationRecipient, repository::RepositoryKind, schema::{ auth::{self, OAuthCredential, OAuthProvider}, @@ -469,18 +469,18 @@ impl DbEnum for thread::Role { } } -impl DbEnum for NotificationKind { +impl DbEnum for NotificationRecipient { fn as_enum_str(&self) -> &'static str { match self { - NotificationKind::Admin => "admin", - NotificationKind::AllUser => "all_user", + NotificationRecipient::Admin => "admin", + NotificationRecipient::AllUser => "all_user", } } fn from_enum_str(s: &str) -> anyhow::Result { match s { - "admin" => Ok(NotificationKind::Admin), - "all_user" => Ok(NotificationKind::AllUser), + "admin" => Ok(NotificationRecipient::Admin), + "all_user" => Ok(NotificationRecipient::AllUser), _ => bail!("{s} is not a valid value for NotificationKind"), } } diff --git a/ee/tabby-schema/src/schema/notification.rs b/ee/tabby-schema/src/schema/notification.rs index aa9712c96a58..a72e3e243173 100644 --- a/ee/tabby-schema/src/schema/notification.rs +++ b/ee/tabby-schema/src/schema/notification.rs @@ -1,7 +1,7 @@ use juniper::GraphQLEnum; #[derive(GraphQLEnum, Clone, Debug)] -pub enum NotificationKind { +pub enum NotificationRecipient { Admin, AllUser, }