| import os |
| import sys |
| from sqlalchemy.orm import Session |
| from app.db.database import SessionLocal, engine |
| from app.db.models import Base, LaborRate, Material, MarginProfile |
|
|
| def seed_database(): |
| """Seed the database with initial data""" |
| |
| db = SessionLocal() |
| |
| try: |
| |
| if db.query(LaborRate).count() > 0: |
| print("Database already seeded. Skipping...") |
| return |
| |
| print("Seeding database...") |
| |
| |
| labor_rates = [ |
| LaborRate(job_type="Kaynakçı", hourly_rate=150.0), |
| LaborRate(job_type="Elektrikçi", hourly_rate=175.0), |
| LaborRate(job_type="Mühendis", hourly_rate=300.0), |
| LaborRate(job_type="Teknisyen", hourly_rate=125.0), |
| LaborRate(job_type="CNC Operatörü", hourly_rate=200.0), |
| ] |
| db.add_all(labor_rates) |
| |
| |
| materials = [ |
| Material(name="Çelik Sac (1mm)", unit="m²", unit_price=250.0), |
| Material(name="Alüminyum Profil", unit="metre", unit_price=120.0), |
| Material(name="Bakır Kablo", unit="metre", unit_price=45.0), |
| Material(name="PLC Kontrol Ünitesi", unit="adet", unit_price=5000.0), |
| Material(name="Sensör", unit="adet", unit_price=750.0), |
| Material(name="Motor (1kW)", unit="adet", unit_price=2500.0), |
| Material(name="Rulman", unit="adet", unit_price=180.0), |
| ] |
| db.add_all(materials) |
| |
| |
| margin_profiles = [ |
| MarginProfile(profile_name="Standart", margin_percentage=0.15), |
| MarginProfile(profile_name="Düşük Rekabet", margin_percentage=0.25), |
| MarginProfile(profile_name="Yüksek Rekabet", margin_percentage=0.10), |
| MarginProfile(profile_name="Stratejik Müşteri", margin_percentage=0.12), |
| MarginProfile(profile_name="Yeni Pazar", margin_percentage=0.08), |
| ] |
| db.add_all(margin_profiles) |
| |
| |
| db.commit() |
| print("Database seeded successfully!") |
| |
| except Exception as e: |
| db.rollback() |
| print(f"Error seeding database: {e}") |
| raise |
| finally: |
| db.close() |
|
|
| if __name__ == "__main__": |
| |
| Base.metadata.create_all(bind=engine) |
| |
| |
| seed_database() |