-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.sql
More file actions
64 lines (57 loc) · 1.99 KB
/
schema.sql
File metadata and controls
64 lines (57 loc) · 1.99 KB
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
-- Enable UUID extension
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
-- Create posts table
CREATE TABLE posts (
id UUID DEFAULT uuid_generate_v4() PRIMARY KEY,
slug TEXT UNIQUE NOT NULL,
title TEXT NOT NULL,
excerpt TEXT,
content TEXT,
date DATE DEFAULT CURRENT_DATE,
author TEXT DEFAULT 'Coding Panda Team',
category TEXT DEFAULT 'general',
read_time INTEGER DEFAULT 5,
cover_color TEXT DEFAULT '#FDE047',
cover_image TEXT,
thumbnail_image TEXT,
likes_count INTEGER DEFAULT 0,
dislikes_count INTEGER DEFAULT 0,
tags TEXT[] DEFAULT '{}',
featured BOOLEAN DEFAULT false,
is_published BOOLEAN DEFAULT false,
use_static_image BOOLEAN DEFAULT false,
created_at TIMESTAMP WITH TIME ZONE DEFAULT timezone('utc'::text, now()) NOT NULL
);
-- Create tags table
CREATE TABLE tags (
id UUID DEFAULT uuid_generate_v4() PRIMARY KEY,
name TEXT UNIQUE NOT NULL,
created_at TIMESTAMP WITH TIME ZONE DEFAULT timezone('utc'::text, now()) NOT NULL
);
-- Create post_interactions table
CREATE TABLE post_interactions (
id UUID DEFAULT uuid_generate_v4() PRIMARY KEY,
post_id UUID REFERENCES posts(id) ON DELETE CASCADE,
session_id TEXT NOT NULL,
type TEXT CHECK (type IN ('like', 'dislike')),
created_at TIMESTAMP WITH TIME ZONE DEFAULT timezone('utc'::text, now()) NOT NULL
);
-- Create profiles table
CREATE TABLE profiles (
id UUID REFERENCES auth.users ON DELETE CASCADE PRIMARY KEY,
full_name TEXT,
email TEXT,
role TEXT DEFAULT 'user',
created_at TIMESTAMP WITH TIME ZONE DEFAULT timezone('utc'::text, now()) NOT NULL
);
-- RLS Policies (Basic examples)
ALTER TABLE posts ENABLE ROW LEVEL SECURITY;
ALTER TABLE tags ENABLE ROW LEVEL SECURITY;
ALTER TABLE post_interactions ENABLE ROW LEVEL SECURITY;
ALTER TABLE profiles ENABLE ROW LEVEL SECURITY;
-- Public can read published posts
CREATE POLICY "Public can read published posts" ON posts
FOR SELECT USING (is_published = true);
-- Public can read tags
CREATE POLICY "Public can read tags" ON tags
FOR SELECT USING (true);