Oliver-ai-bot_2.0/backend/seed_data.py
2026-02-12 19:10:28 +00:00

91 lines
3.3 KiB
Python

"""
Seed Data Script - Populate initial regions and departments
Run this after database migrations: python seed_data.py
"""
import asyncio
import uuid
from datetime import datetime
from sqlalchemy import select
from app.database import AsyncSessionLocal
from app.models.taxonomy import Region, Department
async def seed_data():
"""
Seed initial regions and departments
"""
async with AsyncSessionLocal() as session:
# Check if data already exists
result = await session.execute(select(Region))
existing_regions = result.scalars().all()
if existing_regions:
print("⚠️ Regions already exist. Skipping seed data.")
return
print("🌱 Seeding initial data...")
# Create Regions
regions_data = [
{"code": "UK", "name": "United Kingdom"},
{"code": "US", "name": "United States"},
{"code": "APAC", "name": "Asia Pacific"},
{"code": "EU", "name": "European Union"},
]
regions = {}
for region_data in regions_data:
region = Region(
id=uuid.uuid4(),
code=region_data["code"],
name=region_data["name"],
created_at=datetime.utcnow()
)
session.add(region)
regions[region_data["code"]] = region
print(f" ✓ Created region: {region.code} - {region.name}")
# Create Departments
departments_data = [
# UK Departments
{"region_code": "UK", "code": "HR", "name": "Human Resources"},
{"region_code": "UK", "code": "IT", "name": "Information Technology"},
{"region_code": "UK", "code": "FINANCE", "name": "Finance"},
{"region_code": "UK", "code": "SALES", "name": "Sales"},
{"region_code": "UK", "code": "MARKETING", "name": "Marketing"},
# US Departments
{"region_code": "US", "code": "HR", "name": "Human Resources"},
{"region_code": "US", "code": "IT", "name": "Information Technology"},
{"region_code": "US", "code": "FINANCE", "name": "Finance"},
{"region_code": "US", "code": "SALES", "name": "Sales"},
{"region_code": "US", "code": "LEGAL", "name": "Legal"},
# APAC Departments
{"region_code": "APAC", "code": "SALES", "name": "Sales"},
{"region_code": "APAC", "code": "SUPPORT", "name": "Customer Support"},
{"region_code": "APAC", "code": "IT", "name": "Information Technology"},
# EU Departments
{"region_code": "EU", "code": "HR", "name": "Human Resources"},
{"region_code": "EU", "code": "FINANCE", "name": "Finance"},
]
for dept_data in departments_data:
region = regions[dept_data["region_code"]]
department = Department(
id=uuid.uuid4(),
region_id=region.id,
code=dept_data["code"],
name=dept_data["name"],
created_at=datetime.utcnow()
)
session.add(department)
print(f" ✓ Created department: {region.code}/{department.code} - {department.name}")
await session.commit()
print("✅ Seed data completed successfully!")
if __name__ == "__main__":
asyncio.run(seed_data())