瀏覽代碼

Make user_id consistently BIGINT

Mark Rousskov 5 年之前
父節點
當前提交
3db9fdee17
共有 3 個文件被更改,包括 7 次插入4 次删除
  1. 1 1
      src/db.rs
  2. 5 2
      src/db/notifications.rs
  3. 1 1
      src/handlers.rs

+ 1 - 1
src/db.rs

@@ -63,7 +63,7 @@ CREATE TABLE notifications (
 ",
     "
 CREATE TABLE users (
-    user_id INTEGER PRIMARY KEY,
+    user_id BIGINT PRIMARY KEY,
     username TEXT NOT NULL
 );
 ",

+ 5 - 2
src/db/notifications.rs

@@ -1,3 +1,4 @@
+use anyhow::Context as _;
 use chrono::{DateTime, FixedOffset};
 use tokio_postgres::Client as DbClient;
 
@@ -14,10 +15,12 @@ pub async fn record_ping(db: &DbClient, notification: &Notification) -> anyhow::
         "INSERT INTO users (user_id, username) VALUES ($1, $2) ON CONFLICT DO NOTHING",
         &[&notification.user_id, &notification.username],
     )
-    .await?;
+    .await
+    .context("inserting user id / username")?;
 
     db.execute("INSERT INTO notifications (user_id, origin_url, origin_html, time) VALUES ($1, $2, $3, $4)",
-        &[&notification.user_id, &notification.origin_url, &notification.origin_html, &notification.time]).await?;
+        &[&notification.user_id, &notification.origin_url, &notification.origin_html, &notification.time],
+        ).await.context("inserting notification")?;
 
     Ok(())
 }

+ 1 - 1
src/handlers.rs

@@ -55,7 +55,7 @@ macro_rules! handlers {
             })*
 
             if let Err(e) = notification::handle(ctx, event).await {
-                log::error!("failed to process event {:?} with notification handler: {}", event, e);
+                log::error!("failed to process event {:?} with notification handler: {:?}", event, e);
             }
 
             Ok(())