Dama12 commited on
Commit
b2c15d2
·
1 Parent(s): df2f637

feat(database): enable row level security on all tables

Browse files
alembic/versions/e7b2c9a1d4f8_enable_rls_on_all_tables.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """enable rls on all tables
2
+
3
+ Revision ID: e7b2c9a1d4f8
4
+ Revises: dc6a7b8c9d0e
5
+ Create Date: 2026-05-20 00:15:00.000000
6
+
7
+ """
8
+ from typing import Sequence, Union
9
+ from alembic import op
10
+
11
+ # revision identifiers, used by Alembic.
12
+ revision: str = 'e7b2c9a1d4f8'
13
+ down_revision: Union[str, None] = 'dc6a7b8c9d0e'
14
+ branch_labels: Union[str, Sequence[str], None] = None
15
+ depends_on: Union[str, Sequence[str], None] = None
16
+
17
+ tables = [
18
+ 'users',
19
+ 'projects',
20
+ 'research_papers',
21
+ 'paper_chunks',
22
+ 'analysis_runs',
23
+ 'contradictions',
24
+ 'research_gaps',
25
+ 'experimental_protocols',
26
+ 'reasoning_traces',
27
+ 'exports',
28
+ 'activity_logs'
29
+ ]
30
+
31
+ def upgrade() -> None:
32
+ for table in tables:
33
+ op.execute(f"ALTER TABLE {table} ENABLE ROW LEVEL SECURITY;")
34
+
35
+ def downgrade() -> None:
36
+ for table in tables:
37
+ op.execute(f"ALTER TABLE {table} DISABLE ROW LEVEL SECURITY;")
init_db.sql CHANGED
@@ -165,3 +165,20 @@ CREATE INDEX idx_analysis_project ON analysis_runs(project_id);
165
  CREATE INDEX idx_contradictions_analysis ON contradictions(analysis_id);
166
  CREATE INDEX idx_protocols_analysis ON experimental_protocols(analysis_id);
167
  CREATE INDEX idx_reasoning_analysis ON reasoning_traces(analysis_id);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
165
  CREATE INDEX idx_contradictions_analysis ON contradictions(analysis_id);
166
  CREATE INDEX idx_protocols_analysis ON experimental_protocols(analysis_id);
167
  CREATE INDEX idx_reasoning_analysis ON reasoning_traces(analysis_id);
168
+
169
+ -- ==========================================
170
+ -- ENABLE ROW LEVEL SECURITY (RLS) FOR SUPABASE
171
+ -- ==========================================
172
+
173
+ ALTER TABLE users ENABLE ROW LEVEL SECURITY;
174
+ ALTER TABLE projects ENABLE ROW LEVEL SECURITY;
175
+ ALTER TABLE research_papers ENABLE ROW LEVEL SECURITY;
176
+ ALTER TABLE paper_chunks ENABLE ROW LEVEL SECURITY;
177
+ ALTER TABLE analysis_runs ENABLE ROW LEVEL SECURITY;
178
+ ALTER TABLE contradictions ENABLE ROW LEVEL SECURITY;
179
+ ALTER TABLE research_gaps ENABLE ROW LEVEL SECURITY;
180
+ ALTER TABLE experimental_protocols ENABLE ROW LEVEL SECURITY;
181
+ ALTER TABLE reasoning_traces ENABLE ROW LEVEL SECURITY;
182
+ ALTER TABLE exports ENABLE ROW LEVEL SECURITY;
183
+ ALTER TABLE activity_logs ENABLE ROW LEVEL SECURITY;
184
+