feat: new schema to support user tags better

This commit is contained in:
2025-03-11 20:29:56 +00:00
parent 234988399d
commit c215bf6909

View File

@ -29,9 +29,15 @@ CREATE TABLE haystack.user_images (
user_id uuid NOT NULL REFERENCES haystack.users (id) 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 ( CREATE TABLE haystack.image_tags (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(), 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) 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) image_id UUID NOT NULL REFERENCES haystack.user_images (id)
); );
/* -----| Indexes |----- */
CREATE INDEX user_tags_index ON haystack.user_tags(tag);
/* -----| Stored Procedures |----- */ /* -----| Stored Procedures |----- */
CREATE OR REPLACE FUNCTION notify_new_image() CREATE OR REPLACE FUNCTION notify_new_image()