Source: data_layer/docs/SCHEMA_WORKFLOW.md
Schema Development Workflow
Quick reference for working with JSON Schema and Neo4j Cypher schemas.
Daily Workflow
Adding New Entity
# 1. Create JSON Schema
cat > database/schemas/domain/v1/new_entity.schema.json << 'EOF'
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://altsportsdata.ai/schemas/new_entity.v1.schema.json",
"title": "NewEntity",
"type": "object",
"properties": {
"id": {"type": "string"},
"name": {"type": "string", "minLength": 2}
},
"required": ["id", "name"]
}
EOF
# 2. Generate Pydantic models
./scripts/regenerate_adapters.sh
# 3. Add to Neo4j schema
cat >> database/sql/neo4j_comprehensive_schema.cypher << 'EOF'
// New Entity
CREATE CONSTRAINT new_entity_id_unique IF NOT EXISTS
FOR (n:NewEntity) REQUIRE n.id IS UNIQUE;
CREATE INDEX new_entity_name_idx IF NOT EXISTS
FOR (n:NewEntity) ON (n.name);
EOF
# 4. Document mapping
# Edit database/docs/SCHEMA_MAPPING.md and add entity
# 5. Validate sync
python database/scripts/validate_schema_sync.pyModifying Existing Entity
# 1. Update JSON Schema
# Edit database/schemas/domain/v1/entity_name.schema.json
# 2. Regenerate adapters
./scripts/regenerate_adapters.sh
# 3. Update Neo4j schema
# Edit database/sql/neo4j_comprehensive_schema.cypher
# 4. Apply Neo4j changes (if using Neo4j)
# cypher-shell < database/sql/neo4j_comprehensive_schema.cypher
# 5. Validate sync
python database/scripts/validate_schema_sync.pyAdding Property to Entity
# JSON Schema
# Add to "properties" section
# Neo4j Cypher
# Add to node template properties
# Validate
python database/scripts/validate_schema_sync.pyAdding Relationship
# JSON Schema (optional - may use foreign key pattern)
# Add foreign key field OR array of IDs
# Neo4j Cypher (required)
CREATE (entity1)-[:RELATIONSHIP_TYPE {property: 'value'}]->(entity2)
# Document in SCHEMA_MAPPING.md under "Relationship Mapping Patterns"Common Commands
Validation
# Full validation
python database/scripts/validate_schema_sync.py
# Verbose output
python database/scripts/validate_schema_sync.py --verbose
# Custom base path
python database/scripts/validate_schema_sync.py --base-path /path/to/databaseSchema Generation
# Regenerate all adapters (Python, TypeScript, Drizzle)
./scripts/regenerate_adapters.sh
# Generate specific target
python database/setup/generate_adapters.py --version v1 --target python
python database/setup/generate_adapters.py --version v1 --target typescript
python database/setup/generate_adapters.py --version v1 --target drizzleNeo4j Operations
# Apply Neo4j schema (requires Neo4j running)
cat database/sql/neo4j_comprehensive_schema.cypher | cypher-shell
# Query Neo4j
cypher-shell "MATCH (n) RETURN labels(n), count(n)"
cypher-shell "CALL db.constraints()"
cypher-shell "CALL db.indexes()"Checklist: Adding New Entity
- Create JSON Schema in
database/schemas/domain/v1/ - Run
./scripts/regenerate_adapters.sh - Add Neo4j constraints in
database/sql/neo4j_comprehensive_schema.cypher - Add Neo4j node template with properties
- Define relationships to other entities
- Document in
database/docs/SCHEMA_MAPPING.md - Run
python database/scripts/validate_schema_sync.py - Update tests if needed
Checklist: Modifying Entity
- Update JSON Schema
- Regenerate adapters
- Update Neo4j Cypher schema
- Update mapping documentation
- Run validation script
- Test affected code paths
- Update API documentation
Property Naming Conventions
JSON Schema (snake_case)
{
"league_id": "string",
"full_name": "string",
"website_url": "string"
}Neo4j (camelCase or shortened)
{
id: "string", // league_id β id (shortened)
fullName: "string", // full_name β fullName (camelCase)
websiteUrl: "string" // website_url β websiteUrl (camelCase)
}Document exceptions in SCHEMA_MAPPING.md!
Relationship Patterns
Foreign Key β Relationship
JSON: team.league_id = "LEAGUE_001"
Neo4j: "(team)-[:COMPETES_IN]->(league {id: "LEAGUE_001"})"Array β Multiple Relationships
JSON: league.team_ids = ["TEAM_001", "TEAM_002"]
Neo4j: "(league)<-[:COMPETES_IN]-(team1), (league)<-[:COMPETES_IN]-(team2)"Nested Object β Relationship with Properties
JSON: "player.contract = {start: "2025-01", end: "2026-12"}"
Neo4j: "(player)-[:HAS_CONTRACT {start: date(), end: date()}]->(contract)"Validation Script Output
Success
β
ALL CHECKS PASSED
Summary: 10 JSON entities, 10 Neo4j entitiesFailure
β VALIDATION FAILED (3 errors)
π΄ ERRORS:
β’ Entity "Team" missing in Neo4j
β’ League: JSON property 'website_url' β Neo4j property 'websiteUrl' NOT FOUND
π‘ WARNINGS:
β’ Neo4j has "Sportsbook" entity not in JSON Schema
π‘ SUGGESTIONS:
β’ Add 'websiteUrl' to Neo4j League node
β’ Document mapping in SCHEMA_MAPPING.mdTroubleshooting
Error: "Entity missing in Neo4j"
Fix: Add constraint and node template to neo4j_comprehensive_schema.cypher
Error: "Property mapping not found"
Fix: Either:
- Add property to Neo4j schema
- Document exception in
SCHEMA_MAPPING.mdβ updatevalidate_schema_sync.py
Warning: "Neo4j property not in JSON"
Fix: Consider if property should be:
- Added to JSON Schema (if client-facing)
- Kept Neo4j-only (if internal/computed)
- Documented as Neo4j-specific
Validation script not finding schemas
Fix: Check paths:
ls database/schemas/domain/v1/
ls database/sql/neo4j_comprehensive_schema.cypherIntegration with CI/CD
Add to .github/workflows/validate.yml:
name: Validate Schemas
on: [push, pull_request]
jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Validate schema sync
run: python database/scripts/validate_schema_sync.py
- name: Generate adapters (test)
run: ./scripts/regenerate_adapters.shResources
- SCHEMA_MAPPING.md - Detailed mapping documentation
- JSON Schema Reference (opens in a new tab)
- Neo4j Cypher Manual (opens in a new tab)
- Parent CLAUDE.md - Database architecture
Questions?
Q: Should I use GraphQL? A: No. GraphQL is a query language, not a schema definition system. Use JSON Schema for validation and Neo4j Cypher for graph topology.
Q: Can I add x-graph extensions to JSON Schema?
A: No. Keep concerns separated. JSON Schema = validation, Neo4j = relationships.
Q: How do I keep schemas in sync? A: "Follow this workflow + run validation script regularly. Future: unified YAML spec."
Q: Can I auto-generate one schema from the other? A: "Not currently. Future enhancement: unified spec β generate both. For now: manual sync + validation."
Last Updated: 2025-01-14