From 41f10c18cf4b8be481370b9cc2190b1f8a487bc5 Mon Sep 17 00:00:00 2001 From: Dylan De Faoite Date: Tue, 24 Feb 2026 14:13:41 +0000 Subject: [PATCH] feat: add nlp cols to database schema --- db/database.py | 3 +++ db/schema.sql | 48 ++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 45 insertions(+), 6 deletions(-) diff --git a/db/database.py b/db/database.py index f06dcde..4f2209e 100644 --- a/db/database.py +++ b/db/database.py @@ -30,6 +30,7 @@ class PostgresConnector: cursor.executemany(query, param_list) self.connection.commit() + ## User Management Methods def save_user(self, username, email, password_hash): query = """ INSERT INTO users (username, email, password_hash) @@ -46,6 +47,8 @@ class PostgresConnector: query = "SELECT id, username, email, password_hash FROM users WHERE email = %s" result = self.execute(query, (email,), fetch=True) return result[0] if result else None + + # Dataset Management Methods def close(self): if self.connection: diff --git a/db/schema.sql b/db/schema.sql index e4551d5..d7c8636 100644 --- a/db/schema.sql +++ b/db/schema.sql @@ -6,30 +6,66 @@ CREATE TABLE users ( created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ); -CREATE TABLE has_access ( +CREATE TABLE datasets ( id SERIAL PRIMARY KEY, user_id INTEGER NOT NULL, - post_id INTEGER NOT NULL, - FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE, - FOREIGN KEY (post_id) REFERENCES posts(id) ON DELETE CASCADE + name VARCHAR(255) NOT NULL, + description TEXT, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + nlp_completed BOOLEAN DEFAULT FALSE, + FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE ); CREATE TABLE posts ( id SERIAL PRIMARY KEY, + dataset_id INTEGER NOT NULL, + author VARCHAR(255) NOT NULL, title VARCHAR(255) NOT NULL, content TEXT NOT NULL, created_at TIMESTAMP NOT NULL, - source VARCHAR(255) NOT NULL + source VARCHAR(255) NOT NULL, + + topic VARCHAR(255), + topic_confidence FLOAT, + + ner_entities JSONB, + + emotion_anger FLOAT, + emotion_disgust FLOAT, + emotion_fear FLOAT, + emotion_joy FLOAT, + emotion_neutral FLOAT, + emotion_sadness FLOAT, + emotion_surprise FLOAT, + + FOREIGN KEY (dataset_id) REFERENCES datasets(id) ON DELETE CASCADE ); CREATE TABLE comments ( id SERIAL PRIMARY KEY, + dataset_id INTEGER NOT NULL, + post_id INTEGER NOT NULL, author VARCHAR(255) NOT NULL, content TEXT NOT NULL, created_at TIMESTAMP NOT NULL, reply_to VARCHAR(255), source VARCHAR(255) NOT NULL, - FOREIGN KEY (post_id) REFERENCES posts(id) ON DELETE CASCADE + + topic VARCHAR(255), + topic_confidence FLOAT, + + ner_entities JSONB, + + emotion_anger FLOAT, + emotion_disgust FLOAT, + emotion_fear FLOAT, + emotion_joy FLOAT, + emotion_neutral FLOAT, + emotion_sadness FLOAT, + emotion_surprise FLOAT, + + FOREIGN KEY (post_id) REFERENCES posts(id) ON DELETE CASCADE, + FOREIGN KEY (dataset_id) REFERENCES datasets(id) ON DELETE CASCADE ); \ No newline at end of file