-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhasura-step1-tables.sql
More file actions
26 lines (24 loc) · 928 Bytes
/
hasura-step1-tables.sql
File metadata and controls
26 lines (24 loc) · 928 Bytes
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
-- Step 1: Create Tables Only
-- Run this first if you're having issues with the full script
-- Create chats table
CREATE TABLE public.chats (
id uuid DEFAULT gen_random_uuid() NOT NULL,
title text NOT NULL,
user_id uuid NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (user_id) REFERENCES auth.users(id) ON DELETE CASCADE
);
-- Create messages table
CREATE TABLE public.messages (
id uuid DEFAULT gen_random_uuid() NOT NULL,
chat_id uuid NOT NULL,
user_id uuid NOT NULL,
content text NOT NULL,
is_bot boolean DEFAULT false NOT NULL,
created_at timestamp with time zone DEFAULT now() NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (chat_id) REFERENCES public.chats(id) ON DELETE CASCADE,
FOREIGN KEY (user_id) REFERENCES auth.users(id) ON DELETE CASCADE
);