-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_workgroups.py
More file actions
154 lines (131 loc) · 5.49 KB
/
check_workgroups.py
File metadata and controls
154 lines (131 loc) · 5.49 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/usr/bin/env python3
"""
Diagnostic script to check workgroups table in Supabase.
This will help identify why only 1 workgroup is showing in the Supabase table editor.
"""
from connect import cursor, get_tables, fetch_table
def main():
print("=" * 60)
print("Workgroups Table Diagnostic")
print("=" * 60)
# Get all tables
tables = get_tables()
print(f"\nFound {len(tables)} tables in database:")
for table in tables:
print(f" - {table}")
# Look for workgroup-related tables
workgroup_tables = [t for t in tables if 'workgroup' in t.lower()]
if not workgroup_tables:
print("\n⚠️ No table with 'workgroup' in the name found.")
print(" Checking all tables for workgroup-related data...")
# Check each table for workgroup columns
for table in tables:
cursor.execute("""
SELECT column_name
FROM information_schema.columns
WHERE table_schema = 'public'
AND table_name = %s
AND column_name ILIKE '%workgroup%'
""", (table,))
cols = cursor.fetchall()
if cols:
print(f"\n Found workgroup columns in '{table}':")
for col in cols:
print(f" - {col[0]}")
else:
print(f"\n✓ Found {len(workgroup_tables)} workgroup table(s):")
for table in workgroup_tables:
print(f" - {table}")
# Check each workgroup table
for table in workgroup_tables:
print(f"\n{'=' * 60}")
print(f"Analyzing table: {table}")
print(f"{'=' * 60}")
# Count total rows
cursor.execute(f"SELECT COUNT(*) FROM {table}")
total_count = cursor.fetchone()[0]
print(f"\nTotal rows in database: {total_count}")
# Check for RLS policies
cursor.execute("""
SELECT schemaname, tablename, policyname, permissive, roles, cmd, qual
FROM pg_policies
WHERE tablename = %s
""", (table,))
policies = cursor.fetchall()
if policies:
print(f"\n⚠️ Row Level Security (RLS) policies found: {len(policies)}")
print(" These policies may filter what you see in Supabase UI:")
for policy in policies:
print(f" - Policy: {policy[2]}")
print(f" Command: {policy[5]}")
print(f" Roles: {policy[4]}")
if policy[6]:
print(f" Condition: {policy[6]}")
else:
print("\n✓ No RLS policies found (all rows should be visible)")
# Check if RLS is enabled
cursor.execute("""
SELECT tablename, rowsecurity
FROM pg_tables
WHERE schemaname = 'public'
AND tablename = %s
""", (table,))
rls_info = cursor.fetchall()
if rls_info:
rls_enabled = rls_info[0][1]
if rls_enabled:
print("\n⚠️ RLS (Row Level Security) is ENABLED on this table")
print(" This means policies may be filtering results in Supabase UI")
else:
print("\n✓ RLS is disabled (all rows should be visible)")
# Fetch all rows to see what we get
print(f"\nFetching all rows from {table}...")
try:
rows = fetch_table(table)
print(f"✓ Retrieved {len(rows)} rows via Python connection")
if len(rows) != total_count:
print(f"\n⚠️ MISMATCH: Database has {total_count} rows, but fetch_table() got {len(rows)}")
print(" This suggests filtering is happening somewhere.")
else:
print(f"✓ Row count matches: {len(rows)} rows")
# Show first few rows
if rows:
print(f"\nFirst {min(5, len(rows))} rows:")
for i, row in enumerate(rows[:5], 1):
print(f" {i}. {row}")
except Exception as e:
print(f"✗ Error fetching rows: {e}")
# Check for views that might be filtering
cursor.execute("""
SELECT table_name
FROM information_schema.views
WHERE table_schema = 'public'
AND table_name ILIKE '%workgroup%'
""")
views = cursor.fetchall()
if views:
print(f"\n⚠️ Found {len(views)} view(s) with 'workgroup' in name:")
for view in views:
print(f" - {view[0]}")
print(" Make sure you're looking at the TABLE, not a VIEW in Supabase UI")
print("\n" + "=" * 60)
print("Common reasons for missing rows in Supabase UI:")
print("=" * 60)
print("""
1. Row Level Security (RLS) policies filtering results
→ Check the policies shown above
→ Disable RLS or adjust policies if needed
2. Pagination in Supabase UI
→ Check if there's a "Load more" or pagination control
→ Supabase UI may show limited rows per page
3. Default filters in Supabase UI
→ Check for any filter icons or WHERE clauses in the UI
→ Clear all filters
4. Viewing a VIEW instead of a TABLE
→ Make sure you're in the "Tables" section, not "Views"
5. Connection/user permissions
→ The user account may have limited permissions
→ Check if you're using the correct database role
""")
if __name__ == "__main__":
main()