from app.database import supabase import hashlib def get_password_hash(password: str): return hashlib.sha256(password.encode()).hexdigest() def seed(): # 1. Create a system user if none exists email = "system@meloon.top" password = "system-password-123" # Check if user exists res = supabase.table("users").select("id").eq("email", email).execute() if res.data: system_user_id = res.data[0]["id"] print(f"System user exists with ID: {system_user_id}") else: # Create user print("Creating system user...") user_data = { "email": email, "password_hash": get_password_hash(password) } res = supabase.table("users").insert(user_data).execute() system_user_id = res.data[0]["id"] print(f"Created system user with ID: {system_user_id}") # 2. Seed items from initial_tools.py from app.data.initial_tools import INITIAL_TOOLS_DATA tools_list = [] games_list = [] prompts_list = [] for item in INITIAL_TOOLS_DATA: formatted_item = { "id": item["id"], "name": item["name"], "description": item["description"], "url": item["url"], "category": item["category"], "tags": item.get("tags", []), "likes": item.get("likes", 0), "added_at": item["addedAt"], "image_url": item.get("imageUrl"), "i18n": item.get("i18n", {}), "user_id": system_user_id } if item["category"] == "game": games_list.append(formatted_item) elif item["category"] == "prompt": prompts_list.append(formatted_item) else: tools_list.append(formatted_item) # Seed Tools if tools_list: print(f"Seeding {len(tools_list)} tools...") supabase.table("tools").upsert(tools_list).execute() # Seed Games if games_list: print(f"Seeding {len(games_list)} games...") supabase.table("games").upsert(games_list).execute() # Seed Prompts if prompts_list: print(f"Seeding {len(prompts_list)} prompts...") supabase.table("prompts").upsert(prompts_list).execute() # Cleanup: Remove games and prompts from tools table if they exists there print("Cleaning up tools table...") supabase.table("tools").delete().in_("category", ["game", "prompt"]).execute() print("Seed complete.") if __name__ == "__main__": seed()