FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
SQLeditor_/create_user_programs_table.sql at main · syntax-error002/SQLeditor_ · GitHub
syntax-error002
/
SQLeditor_
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
2
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
SQLeditor_
/
create_user_programs_table.sql
Copy path
More file actions
More file actions
Latest commit
History
History
History
40 lines (34 loc) · 1.25 KB
Breadcrumbs
SQLeditor_
/
create_user_programs_table.sql
Copy path
File metadata and controls
40 lines (34 loc) · 1.25 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
--
Create the user_programs table
CREATE
TABLE
IF
NOT EXISTS user_programs (
id UUID
PRIMARY KEY
DEFAULT gen_random_uuid(),
user_id UUID
NOT NULL
REFERENCES
auth
.
users
(id)
ON DELETE CASCADE
,
name
TEXT
NOT NULL
,
sql
TEXT
NOT NULL
,
created_at
TIMESTAMPTZ
NOT NULL
DEFAULT NOW(),
updated_at
TIMESTAMPTZ
NOT NULL
DEFAULT NOW()
);
--
Create index for faster queries
CREATE
INDEX
IF
NOT EXISTS user_programs_user_id_idx
ON
user_programs(user_id);
--
Set up Row Level Security (RLS)
ALTER
TABLE
user_programs ENABLE ROW LEVEL SECURITY;
--
Create policies
--
Policy to allow users to select only their own programs
CREATE POLICY
"
Users can view their own programs
"
ON
user_programs
FOR
SELECT
USING (
auth
.
uid
()
=
user_id);
--
Policy to allow users to insert their own programs
CREATE POLICY
"
Users can insert their own programs
"
ON
user_programs
FOR INSERT
WITH
CHECK
(
auth
.
uid
()
=
user_id);
--
Policy to allow users to update only their own programs
CREATE POLICY
"
Users can update their own programs
"
ON
user_programs
FOR
UPDATE
USING (
auth
.
uid
()
=
user_id);
--
Policy to allow users to delete only their own programs
CREATE POLICY
"
Users can delete their own programs
"
ON
user_programs
FOR
DELETE
USING (
auth
.
uid
()
=
user_id);
Back
|
FazBrowse Home
|
New Git URL