Files
service-finder/backend/app/scripts/init_mlm_parameters_fixed.py
2026-06-04 07:26:22 +00:00

58 lines
2.2 KiB
Python

#!/usr/bin/env python3
"""
MLM és Gamification paraméterek inicializálása a system_parameters táblába.
Futtatás: docker compose exec sf_api python3 /app/backend/app/scripts/init_mlm_parameters_fixed.py
"""
import asyncio
import sys
import os
sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy import select
from app.models.system.system import SystemParameter, ParameterScope
from app.core.config import settings
async def init_parameters():
engine = create_async_engine(settings.DATABASE_URL, echo=False)
async_session = sessionmaker(engine, class_=AsyncSession, expire_on_commit=False)
async with async_session() as session:
# MLM százalékok
mlm_params = [
("mlm_level1_percent", 10, "MLM L1 jutalék százalék (10%)", ParameterScope.GLOBAL),
("mlm_level2_percent", 5, "MLM L2 jutalék százalék (5%)", ParameterScope.GLOBAL),
("mlm_level3_percent", 3, "MLM L3 jutalék százalék (3%)", ParameterScope.GLOBAL),
("gamification_p2p_invite_xp", 50, "XP pontok a meghívónak sikeres KYC után", ParameterScope.GLOBAL),
]
for key, value, description, scope in mlm_params:
existing = await session.execute(
select(SystemParameter).where(SystemParameter.key == key)
)
if existing.scalar_one_or_none():
print(f"{key} már létezik, kihagyva.")
continue
param = SystemParameter(
key=key,
value={"value": value},
category="mlm",
scope_level=scope,
scope_id=None,
is_active=True,
description=description,
last_modified_by=None,
)
session.add(param)
print(f"{key} = {value} beállítva.")
await session.commit()
print("✅ MLM paraméterek sikeresen inicializálva.")
if __name__ == "__main__":
asyncio.run(init_parameters())