File size: 3,231 Bytes
f8553c9 46efd9c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 | -- Drop tables if they exist
DROP TABLE IF EXISTS public.tools;
DROP TABLE IF EXISTS public.users;
-- Create the users table
CREATE TABLE public.users (
id UUID DEFAULT gen_random_uuid() PRIMARY KEY,
email TEXT UNIQUE NOT NULL,
password_hash TEXT NOT NULL,
created_at TIMESTAMPTZ DEFAULT now()
);
-- Create the tools table
CREATE TABLE IF NOT EXISTS public.tools (
id TEXT PRIMARY KEY,
name TEXT NOT NULL,
description TEXT NOT NULL,
url TEXT NOT NULL,
category TEXT NOT NULL,
tags TEXT[] DEFAULT '{}',
likes INTEGER DEFAULT 0,
added_at BIGINT NOT NULL,
image_url TEXT,
i18n JSONB NOT NULL,
user_id UUID REFERENCES public.users(id) ON DELETE CASCADE
);
-- Create the games table
CREATE TABLE IF NOT EXISTS public.games (
id TEXT PRIMARY KEY,
name TEXT NOT NULL,
description TEXT NOT NULL,
url TEXT NOT NULL,
category TEXT NOT NULL DEFAULT 'game',
tags TEXT[] DEFAULT '{}',
likes INTEGER DEFAULT 0,
added_at BIGINT NOT NULL,
image_url TEXT,
i18n JSONB NOT NULL,
user_id UUID REFERENCES public.users(id) ON DELETE CASCADE
);
-- Create the prompts table
CREATE TABLE IF NOT EXISTS public.prompts (
id TEXT PRIMARY KEY,
name TEXT NOT NULL,
description TEXT NOT NULL,
url TEXT NOT NULL,
category TEXT NOT NULL DEFAULT 'prompt',
tags TEXT[] DEFAULT '{}',
likes INTEGER DEFAULT 0,
added_at BIGINT NOT NULL,
image_url TEXT,
i18n JSONB NOT NULL,
user_id UUID REFERENCES public.users(id) ON DELETE CASCADE
);
-- Dynamics table
CREATE TABLE IF NOT EXISTS public.dynamics (
id UUID DEFAULT gen_random_uuid() PRIMARY KEY,
title TEXT NOT NULL,
content TEXT NOT NULL,
url TEXT,
source TEXT,
category TEXT,
published_at TIMESTAMPTZ DEFAULT now()
);
-- Performance Indexes for Search
CREATE INDEX IF NOT EXISTS idx_tools_name_description ON public.tools USING gin(to_tsvector('english', name || ' ' || description));
CREATE INDEX IF NOT EXISTS idx_games_name_description ON public.games USING gin(to_tsvector('english', name || ' ' || description));
CREATE INDEX IF NOT EXISTS idx_prompts_name_description ON public.prompts USING gin(to_tsvector('english', name || ' ' || description));
-- Ratings table
CREATE TABLE IF NOT EXISTS public.ratings (
id UUID DEFAULT gen_random_uuid() PRIMARY KEY,
item_id TEXT NOT NULL,
item_type TEXT NOT NULL CHECK (item_type IN ('tool', 'game', 'prompt')),
user_id UUID REFERENCES public.users(id) ON DELETE CASCADE,
rating INTEGER NOT NULL CHECK (rating >= 1 AND rating <= 5),
created_at TIMESTAMPTZ DEFAULT now(),
UNIQUE(item_id, item_type, user_id)
);
-- Comments table
CREATE TABLE IF NOT EXISTS public.comments (
id UUID DEFAULT gen_random_uuid() PRIMARY KEY,
item_id TEXT NOT NULL,
item_type TEXT NOT NULL CHECK (item_type IN ('tool', 'game', 'prompt')),
user_id UUID REFERENCES public.users(id) ON DELETE CASCADE,
content TEXT NOT NULL,
created_at TIMESTAMPTZ DEFAULT now()
);
-- Indexes for performance
CREATE INDEX IF NOT EXISTS idx_ratings_item ON public.ratings(item_id, item_type);
CREATE INDEX IF NOT EXISTS idx_comments_item ON public.comments(item_id, item_type);
|