From 5df6c67ee542edac2cf2f54295cb9b2017fe9dbd Mon Sep 17 00:00:00 2001 From: John Costa Date: Tue, 11 Mar 2025 20:29:56 +0000 Subject: [PATCH] feat: new schema to support user tags better --- backend/schema.sql | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/backend/schema.sql b/backend/schema.sql index 26b9dbc..5a27869 100644 --- a/backend/schema.sql +++ b/backend/schema.sql @@ -29,9 +29,15 @@ CREATE TABLE haystack.user_images ( user_id uuid NOT NULL REFERENCES haystack.users (id) ); +CREATE TABLE haystack.user_tags ( + id uuid PRIMARY KEY DEFAULT gen_random_uuid(), + tag VARCHAR(32) NOT NULL, + user_id uuid NOT NULL REFERENCES haystack.users (id) +); + CREATE TABLE haystack.image_tags ( id uuid PRIMARY KEY DEFAULT gen_random_uuid(), - tag TEXT NOT NULL, + tag_id UUID NOT NULL REFERENCES haystack.user_tags (id), image_id UUID NOT NULL REFERENCES haystack.user_images (id) ); @@ -47,6 +53,10 @@ CREATE TABLE haystack.image_links ( image_id UUID NOT NULL REFERENCES haystack.user_images (id) ); +/* -----| Indexes |----- */ + +CREATE INDEX user_tags_index ON haystack.user_tags(tag); + /* -----| Stored Procedures |----- */ CREATE OR REPLACE FUNCTION notify_new_image()