Files
deals24togo_be/scripts/seed.py
belviskhoremk c4d836a0f9 Initial commit
2026-03-06 22:57:58 +00:00

71 lines
2.1 KiB
Python
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Seed script — creates an admin user and sample data via Supabase Auth.
Usage:
python -m scripts.seed
"""
import os
import sys
# Add project root to path
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from dotenv import load_dotenv
load_dotenv()
from app.core.supabase import get_supabase_admin
def _create_user(db, email: str, password: str, name: str, role: str, with_agency: bool = False):
"""Create a Supabase Auth user + profile row. Skip if already exists."""
existing = db.table("users").select("id").eq("email", email).execute()
if existing.data:
print(f" User already exists: {email}")
return
auth_response = db.auth.admin.create_user({
"email": email,
"password": password,
"email_confirm": True,
})
user_id = auth_response.user.id
db.table("users").insert({
"id": user_id,
"email": email,
"name": name,
"role": role,
"verified": True,
}).execute()
if with_agency:
db.table("agencies").insert({
"user_id": user_id,
"name": "Demo Real Estate Agency",
"description": "A demo agency for testing the platform.",
"address": "123 Demo Street, Lomé, Togo",
"phone": "+228 90 00 00 00",
"email": email,
"website": "https://demo-agency.deals24togo.com",
"verified": True,
}).execute()
print(f"✅ Created {role}: {email} / {password}")
def seed():
db = get_supabase_admin()
_create_user(db, "admin@deals24togo.com", "admin123456", "Admin", "admin")
_create_user(db, "agency@deals24togo.com", "agency123456", "Demo Agency", "agency", with_agency=True)
_create_user(db, "visitor@deals24togo.com", "visitor123456", "Demo Visitor", "visitor")
print("\n🎉 Seeding complete!")
print(" Admin: admin@deals24togo.com / admin123456")
print(" Agency: agency@deals24togo.com / agency123456")
print(" Visitor: visitor@deals24togo.com / visitor123456")
if __name__ == "__main__":
seed()