From 6e6f2ce7c24acabdfd1f1f59378467ea225fb27a Mon Sep 17 00:00:00 2001
From: Santo Cariotti <santo@dcariotti.me>
Date: Mon, 26 Aug 2024 22:07:42 +0200
Subject: Add alerts

A payload for alert creation can be

```
{
  "query": "mutation NewAlert($input: AlertInput!) { newAlert(input: $input) { id createdAt level } }",
  "variables": {
    "input": {
      "points": [
        { "latitude": 40.73061, "longitude": -73.935242 },
        { "latitude": 40.741895, "longitude": -73.989308 },
        { "latitude": 40.712776, "longitude": -74.005974 },
        { "latitude": 40.73061, "longitude": -73.935242 },
      ],
      "level": "TWO"
    }
  }
}
```
---
 schema/init.sql | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

(limited to 'schema/init.sql')

diff --git a/schema/init.sql b/schema/init.sql
index 682431c..8950a5f 100644
--- a/schema/init.sql
+++ b/schema/init.sql
@@ -18,3 +18,17 @@ CREATE TABLE positions(
     CONSTRAINT fk_users_id
         FOREIGN KEY(user_id) REFERENCES users(id)
 );
+
+CREATE TYPE level_alert AS ENUM ('One', 'Two', 'Three');
+
+CREATE TABLE alerts(
+    id SERIAL NOT NULL,
+    user_id INTEGER NOT NULL,
+    created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
+    area GEOMETRY(Polygon, 4326),
+    level level_alert NOT NULL,
+    reached_users INTEGER DEFAULT 0 NOT NULL,
+    PRIMARY KEY(id),
+    CONSTRAINT fk_users_id
+        FOREIGN KEY(user_id) REFERENCES users(id)
+);
-- 
cgit v1.2.3-71-g8e6c

