File size: 1,585 Bytes
c6abe34 | 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 | import asyncio
import os
import sys
# Add the parent directory to sys.path to allow importing app
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
from app.services.supabase_client import get_supabase_service
async def clear_database():
"""
Clears all data from the database tables while preserving the schema.
"""
supabase = get_supabase_service()
# Order matters due to foreign key constraints if not using cascade
# However, supabase.delete often requires a filter, or we can use SQL truncate
# Since we use the service wrapper, let's try to delete with a broad filter
# or expose a raw SQL execution method if available.
tables = [
"activities",
"notifications",
"matches",
"schedules",
"analytics",
"analysis_results",
"detections",
"videos",
"players",
"organizations",
"users"
]
print("Starting database clear...")
for table in tables:
try:
print(f"Clearing table: {table}...")
# Use the internal _run_sync because .execute() is synchronous in this version of supabase-py
await supabase._run_sync(lambda: supabase.client.table(table).delete().neq("id", "00000000-0000-0000-0000-000000000000").execute())
print(f"Successfully cleared {table}")
except Exception as e:
print(f"Error clearing table {table}: {e}")
print("Database clear complete.")
if __name__ == "__main__":
asyncio.run(clear_database())
|