File size: 2,568 Bytes
f8553c9 | 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 |
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()
|