Implement complete member management system with GraphQL API per OpenSpec proposal. Only firstName is required; all other fields are optional with conditional validation. Key features: - GraphQL CRUD operations (create, read, update, delete members) - SQLAlchemy 2.0 async with SQLite database - Alembic database migrations - Conditional validation (email/phone validated only when provided) - Member fields: firstName (required), lastName, address, email, phone (all optional) - Database seed script with sample member - FastAPI with Strawberry GraphQL integration Implementation details: - Python 3.11+ with uv package manager - Async database sessions throughout - Proper error handling and validation - Code quality: black, isort, ruff - Comprehensive end-to-end testing completed All 20 tasks from OpenSpec proposal completed successfully. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
51 lines
1.7 KiB
Python
51 lines
1.7 KiB
Python
#!/usr/bin/env python
|
|
"""Seed database with sample member data."""
|
|
import asyncio
|
|
|
|
from sqlalchemy import select
|
|
|
|
from src.database import async_session_maker
|
|
from src.models.member import Member
|
|
|
|
|
|
async def seed_database():
|
|
"""Create sample member if it doesn't exist."""
|
|
async with async_session_maker() as session:
|
|
# Check if sample member already exists
|
|
result = await session.execute(
|
|
select(Member).where(Member.email == "jane.doe@example.com")
|
|
)
|
|
existing_member = result.scalar_one_or_none()
|
|
|
|
if existing_member:
|
|
print("✓ Sample member already exists")
|
|
print(f" ID: {existing_member.id}")
|
|
print(f" Name: {existing_member.first_name} {existing_member.last_name}")
|
|
print(f" Email: {existing_member.email}")
|
|
return
|
|
|
|
# Create sample member with minimal required data
|
|
# Demonstrates that only firstName is required
|
|
sample_member = Member(
|
|
first_name="Jane",
|
|
last_name="Doe",
|
|
email="jane.doe@example.com",
|
|
# All other fields (street, zip, city, country, phone) are None
|
|
)
|
|
|
|
session.add(sample_member)
|
|
await session.commit()
|
|
await session.refresh(sample_member)
|
|
|
|
print("✓ Sample member created successfully!")
|
|
print(f" ID: {sample_member.id}")
|
|
print(f" Name: {sample_member.first_name} {sample_member.last_name}")
|
|
print(f" Email: {sample_member.email}")
|
|
print(f" Created at: {sample_member.created_at}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
print("Seeding database...")
|
|
asyncio.run(seed_database())
|
|
print("Done!")
|