-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcreate_profiles_table.py
More file actions
67 lines (53 loc) · 1.84 KB
/
Copy pathcreate_profiles_table.py
File metadata and controls
67 lines (53 loc) · 1.84 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
65
66
67
#!/usr/bin/env python3
import psycopg2
import sys
DB_CONFIG = {
'host': 'aws-1-us-east-1.pooler.supabase.com',
'port': 5432,
'user': 'postgres.lwexhbimtxpndhsidogl',
'password': 'elvpfW5zDRe76XwS',
'database': 'postgres',
}
def create_profiles_table():
try:
conn = psycopg2.connect(**DB_CONFIG)
conn.autocommit = True
cursor = conn.cursor()
print("📝 Creating profiles table...")
cursor.execute("""
CREATE TABLE IF NOT EXISTS profiles (
id UUID PRIMARY KEY REFERENCES auth.users(id) ON DELETE CASCADE,
resume TEXT,
resume_name TEXT,
resume_url TEXT,
resume_updated_at TIMESTAMP WITH TIME ZONE,
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);
""")
print("✅ Table created")
print("📝 Creating RLS policies...")
cursor.execute("""
ALTER TABLE profiles ENABLE ROW LEVEL SECURITY;
""")
cursor.execute("""
CREATE POLICY "Users can view their own profile" ON profiles
FOR SELECT USING (auth.uid() = id);
""")
cursor.execute("""
CREATE POLICY "Users can update their own profile" ON profiles
FOR UPDATE USING (auth.uid() = id);
""")
cursor.execute("""
CREATE POLICY "Users can insert their own profile" ON profiles
FOR INSERT WITH CHECK (auth.uid() = id);
""")
print("✅ RLS policies created")
cursor.close()
conn.close()
print("\n✅ Profiles table setup complete!")
except psycopg2.Error as e:
print(f"❌ Error: {e}")
sys.exit(1)
if __name__ == '__main__':
create_profiles_table()