From 1c3d072de12f3319cf40fad592835d5dfb301e70 Mon Sep 17 00:00:00 2001
From: Santo Cariotti <santo@dcariotti.me>
Date: Sun, 20 Oct 2024 21:58:58 +0200
Subject: Save notification's position info

Since we save the last user's position only, we can't be able to link a
notification to a position. So, the better thing is to save a redundant lat/lng
---
 schema/init.sql | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

(limited to 'schema/init.sql')

diff --git a/schema/init.sql b/schema/init.sql
index f6a1fbd..68f1f92 100644
--- a/schema/init.sql
+++ b/schema/init.sql
@@ -44,7 +44,9 @@ CREATE TABLE alerts(
 CREATE TABLE notifications(
     id SERIAL NOT NULL,
     alert_id INTEGER NOT NULL,
-    position_id INTEGER NOT NULL,
+    user_id INTEGER NOT NULL,
+    location GEOGRAPHY(Point, 4326) NOT NULL,
+    activity moving_activity NOT NULL,
     seen BOOLEAN DEFAULT false,
     level level_alert NOT NULL,
     created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
@@ -52,7 +54,7 @@ CREATE TABLE notifications(
     CONSTRAINT fk_alerts_id
         FOREIGN KEY(alert_id) REFERENCES alerts(id)
         ON DELETE CASCADE,
-    CONSTRAINT fk_positions_id
-        FOREIGN KEY(position_id) REFERENCES positions(id)
+    CONSTRAINT fk_users_id
+        FOREIGN KEY(user_id) REFERENCES users(id)
         ON DELETE CASCADE
 );
-- 
cgit v1.2.3-71-g8e6c

