admin_szolgáltatók_
This commit is contained in:
53
backend/app/scripts/check_provider_validations.py
Normal file
53
backend/app/scripts/check_provider_validations.py
Normal file
@@ -0,0 +1,53 @@
|
||||
"""
|
||||
Check if provider_validations table exists and create if not.
|
||||
"""
|
||||
import asyncio
|
||||
from sqlalchemy import text
|
||||
from sqlalchemy.ext.asyncio import create_async_engine
|
||||
from app.core.config import settings
|
||||
|
||||
|
||||
async def main():
|
||||
engine = create_async_engine(str(settings.SQLALCHEMY_DATABASE_URI))
|
||||
|
||||
async with engine.connect() as conn:
|
||||
# Check if table exists
|
||||
result = await conn.execute(
|
||||
text("SELECT EXISTS (SELECT FROM information_schema.tables WHERE table_schema = 'marketplace' AND table_name = 'provider_validations')")
|
||||
)
|
||||
exists = result.scalar()
|
||||
print(f"provider_validations table exists: {exists}")
|
||||
|
||||
if not exists:
|
||||
# Create the table
|
||||
await conn.execute(text("""
|
||||
CREATE TABLE IF NOT EXISTS marketplace.provider_validations (
|
||||
id SERIAL PRIMARY KEY,
|
||||
provider_id INTEGER NOT NULL REFERENCES marketplace.service_providers(id) ON DELETE CASCADE,
|
||||
voter_user_id INTEGER NOT NULL REFERENCES identity.users(id) ON DELETE CASCADE,
|
||||
validation_type VARCHAR(20) NOT NULL DEFAULT 'approve',
|
||||
weight INTEGER NOT NULL DEFAULT 1,
|
||||
metadata JSONB DEFAULT '{}'::jsonb,
|
||||
created_at TIMESTAMPTZ DEFAULT NOW(),
|
||||
UNIQUE(voter_user_id, provider_id)
|
||||
)
|
||||
"""))
|
||||
await conn.commit()
|
||||
print("Created provider_validations table")
|
||||
|
||||
# Check columns
|
||||
result = await conn.execute(text("""
|
||||
SELECT column_name, data_type, is_nullable
|
||||
FROM information_schema.columns
|
||||
WHERE table_schema = 'marketplace' AND table_name = 'provider_validations'
|
||||
ORDER BY ordinal_position
|
||||
"""))
|
||||
print("\nColumns:")
|
||||
for row in result:
|
||||
print(f" {row.column_name}: {row.data_type} (nullable: {row.is_nullable})")
|
||||
|
||||
await engine.dispose()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
157
backend/app/scripts/seed_gamification_action_keys.py
Normal file
157
backend/app/scripts/seed_gamification_action_keys.py
Normal file
@@ -0,0 +1,157 @@
|
||||
"""
|
||||
Gamification Action Keys Seed Script
|
||||
=====================================
|
||||
Cél: Hiányzó action_key-ek felvétele a gamification.point_rules táblába.
|
||||
|
||||
Az audit során az alábbi akciókhoz NEM létezik action_key a point_rules táblában:
|
||||
- KYC_VERIFICATION (auth_service KYC completion)
|
||||
- P2P_REFERRAL_SUCCESS (auth_service P2P referral)
|
||||
- EXPENSE_LOG (cost_service expense recording)
|
||||
- FLEET_EVENT (fleet_service vehicle event)
|
||||
- PROVIDER_VALIDATED (social_service provider validation)
|
||||
- PROVIDER_REJECTED (social_service provider rejection)
|
||||
- SERVICE_HUNT (services.py service hunt)
|
||||
- SERVICE_VALIDATION (services.py service validation)
|
||||
|
||||
Használat:
|
||||
docker compose exec sf_api python3 /app/backend/app/scripts/seed_gamification_action_keys.py
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import logging
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
# Projekt gyökér hozzáadása a Python path-hoz
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent.parent.parent))
|
||||
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine, async_sessionmaker
|
||||
from app.core.config import settings
|
||||
from app.models.gamification.gamification import PointRule
|
||||
|
||||
logging.basicConfig(level=logging.INFO, format="%(asctime)s [%(levelname)s] %(message)s")
|
||||
logger = logging.getLogger("Seed-Gamification-Action-Keys")
|
||||
|
||||
# Hiányzó action_key-ek a point_rules táblába
|
||||
# Pontértékek a meglévő ConfigService default értékek alapján:
|
||||
# KYC_VERIFICATION = 100 (auth_service: kyc_reward)
|
||||
# P2P_REFERRAL_SUCCESS = 50 (auth_service: gamification_p2p_invite_xp default)
|
||||
# EXPENSE_LOG = 50 (cost_service: xp_per_cost_log default)
|
||||
# FLEET_EVENT = 20 (fleet_service: event_rewards["default"]["xp"])
|
||||
# PROVIDER_VALIDATED = 100 (social_service: hardcoded 100XP)
|
||||
# PROVIDER_REJECTED = 50 (social_service: hardcoded 50XP)
|
||||
# SERVICE_HUNT = 50 (services.py: GAMIFICATION_HUNT_REWARD default)
|
||||
# SERVICE_VALIDATION = 10 (services.py: GAMIFICATION_VALIDATE_REWARD default)
|
||||
SEED_RULES = [
|
||||
{
|
||||
"action_key": "KYC_VERIFICATION",
|
||||
"points": 100,
|
||||
"description": "Sikeres KYC (Know Your Customer) folyamat teljesítése",
|
||||
"is_active": True,
|
||||
},
|
||||
{
|
||||
"action_key": "P2P_REFERRAL_SUCCESS",
|
||||
"points": 50,
|
||||
"description": "Sikeres P2P meghívó (referred_by_id alapján)",
|
||||
"is_active": True,
|
||||
},
|
||||
{
|
||||
"action_key": "EXPENSE_LOG",
|
||||
"points": 50,
|
||||
"description": "Költség rögzítése (base_xp, OCR bónusz nélkül)",
|
||||
"is_active": True,
|
||||
},
|
||||
{
|
||||
"action_key": "FLEET_EVENT",
|
||||
"points": 20,
|
||||
"description": "Flotta esemény rögzítése (alapértelmezett pont)",
|
||||
"is_active": True,
|
||||
},
|
||||
{
|
||||
"action_key": "PROVIDER_VALIDATED",
|
||||
"points": 100,
|
||||
"description": "Provider adatainak közösségi validálása (jóváhagyás)",
|
||||
"is_active": True,
|
||||
},
|
||||
{
|
||||
"action_key": "PROVIDER_REJECTED",
|
||||
"points": 50,
|
||||
"description": "Provider adatainak közösségi elutasítása (büntetés)",
|
||||
"is_active": True,
|
||||
},
|
||||
{
|
||||
"action_key": "SERVICE_HUNT",
|
||||
"points": 50,
|
||||
"description": "Új szerviz felfedezése (service hunt)",
|
||||
"is_active": True,
|
||||
},
|
||||
{
|
||||
"action_key": "SERVICE_VALIDATION",
|
||||
"points": 10,
|
||||
"description": "Szerviz validálása (más user által beküldött staging rekord)",
|
||||
"is_active": True,
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
async def seed_gamification_action_keys():
|
||||
"""
|
||||
Feltölti a gamification.point_rules táblát a hiányzó action_key-ekkel.
|
||||
Csak azokat a rekordokat szúrja be, amelyek még nem léteznek (action_key alapján).
|
||||
"""
|
||||
engine = create_async_engine(settings.DATABASE_URL, echo=False)
|
||||
async_session = async_sessionmaker(engine, class_=AsyncSession, expire_on_commit=False)
|
||||
|
||||
async with async_session() as db:
|
||||
try:
|
||||
inserted_count = 0
|
||||
skipped_count = 0
|
||||
|
||||
for rule_data in SEED_RULES:
|
||||
# Ellenőrizzük, hogy létezik-e már ez a szabály
|
||||
stmt = select(PointRule).where(
|
||||
PointRule.action_key == rule_data["action_key"]
|
||||
)
|
||||
result = await db.execute(stmt)
|
||||
existing = result.scalar_one_or_none()
|
||||
|
||||
if existing:
|
||||
logger.info(
|
||||
f"⏭️ Szabály már létezik: {rule_data['action_key']} "
|
||||
f"(pont: {existing.points}, ID: {existing.id})"
|
||||
)
|
||||
skipped_count += 1
|
||||
continue
|
||||
|
||||
# Új szabály beszúrása
|
||||
new_rule = PointRule(
|
||||
action_key=rule_data["action_key"],
|
||||
points=rule_data["points"],
|
||||
description=rule_data["description"],
|
||||
is_active=rule_data["is_active"],
|
||||
)
|
||||
db.add(new_rule)
|
||||
await db.flush()
|
||||
logger.info(
|
||||
f"✅ Szabály létrehozva: {rule_data['action_key']} "
|
||||
f"(pont: {rule_data['points']}, ID: {new_rule.id})"
|
||||
)
|
||||
inserted_count += 1
|
||||
|
||||
await db.commit()
|
||||
logger.info(
|
||||
f"\n📊 Összegzés: {inserted_count} új szabály beszúrva, "
|
||||
f"{skipped_count} már létezett."
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
await db.rollback()
|
||||
logger.error(f"❌ Hiba a seedelés során: {e}", exc_info=True)
|
||||
raise
|
||||
finally:
|
||||
await engine.dispose()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(seed_gamification_action_keys())
|
||||
124
backend/app/scripts/seed_provider_point_rules.py
Normal file
124
backend/app/scripts/seed_provider_point_rules.py
Normal file
@@ -0,0 +1,124 @@
|
||||
"""
|
||||
Provider Gamification Point Rules Seed Script
|
||||
=============================================
|
||||
Cél: Új gamification pontszabályok beszúrása a provider discovery rendszerhez.
|
||||
|
||||
Új szabályok:
|
||||
- PROVIDER_DISCOVERY (300 pont) — Új provider felfedezése expense rögzítéskor
|
||||
- PROVIDER_CONFIRMATION (150 pont) — Meglévő provider adatainak megerősítése
|
||||
- PROVIDER_VERIFIED_USE (100 pont) — Már validált provider használata
|
||||
|
||||
Használat:
|
||||
docker compose exec sf_api python3 /app/backend/app/scripts/seed_provider_point_rules.py
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import logging
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
# Projekt gyökér hozzáadása a Python path-hoz
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent.parent.parent))
|
||||
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine, async_sessionmaker
|
||||
from app.core.config import settings
|
||||
from app.models.gamification.gamification import PointRule
|
||||
|
||||
logging.basicConfig(level=logging.INFO, format="%(asctime)s [%(levelname)s] %(message)s")
|
||||
logger = logging.getLogger("Seed-Provider-Point-Rules")
|
||||
|
||||
# Új provider discovery pontszabályok
|
||||
# A pontértékek a kártya specifikációja szerint (#356, #362):
|
||||
# PROVIDER_DISCOVERY = 300 — Új provider felfedezése
|
||||
# PROVIDER_CONFIRMATION = 150 — Saját pending provider használata
|
||||
# PROVIDER_VERIFIED_USE = 100 — Már validált provider használata
|
||||
# USE_UNVERIFIED_PROVIDER = 200 — Más user által létrehozott, még pending provider használata
|
||||
SEED_RULES = [
|
||||
{
|
||||
"action_key": "PROVIDER_DISCOVERY",
|
||||
"points": 300,
|
||||
"description": "Új, még nem létező provider felfedezése expense rögzítéskor (external_vendor_name alapján)",
|
||||
"is_active": True,
|
||||
},
|
||||
{
|
||||
"action_key": "PROVIDER_CONFIRMATION",
|
||||
"points": 150,
|
||||
"description": "Saját magad által létrehozott, még pending státuszú provider használata",
|
||||
"is_active": True,
|
||||
},
|
||||
{
|
||||
"action_key": "PROVIDER_VERIFIED_USE",
|
||||
"points": 100,
|
||||
"description": "Már jóváhagyott (approved) provider használata költség rögzítésnél",
|
||||
"is_active": True,
|
||||
},
|
||||
{
|
||||
"action_key": "USE_UNVERIFIED_PROVIDER",
|
||||
"points": 200,
|
||||
"description": "Más user által létrehozott, még pending státuszú provider használata (XP farming prevention)",
|
||||
"is_active": True,
|
||||
},
|
||||
]
|
||||
|
||||
|
||||
async def seed_provider_point_rules():
|
||||
"""
|
||||
Feltölti a gamification.point_rules táblát a provider discovery szabályokkal.
|
||||
Csak azokat a rekordokat szúrja be, amelyek még nem léteznek (action_key alapján).
|
||||
"""
|
||||
engine = create_async_engine(settings.DATABASE_URL, echo=False)
|
||||
async_session = async_sessionmaker(engine, class_=AsyncSession, expire_on_commit=False)
|
||||
|
||||
async with async_session() as db:
|
||||
try:
|
||||
inserted_count = 0
|
||||
skipped_count = 0
|
||||
|
||||
for rule_data in SEED_RULES:
|
||||
# Ellenőrizzük, hogy létezik-e már ez a szabály
|
||||
stmt = select(PointRule).where(
|
||||
PointRule.action_key == rule_data["action_key"]
|
||||
)
|
||||
result = await db.execute(stmt)
|
||||
existing = result.scalar_one_or_none()
|
||||
|
||||
if existing:
|
||||
logger.info(
|
||||
f"⏭️ Szabály már létezik: {rule_data['action_key']} "
|
||||
f"(pont: {existing.points}, ID: {existing.id})"
|
||||
)
|
||||
skipped_count += 1
|
||||
continue
|
||||
|
||||
# Új szabály beszúrása
|
||||
new_rule = PointRule(
|
||||
action_key=rule_data["action_key"],
|
||||
points=rule_data["points"],
|
||||
description=rule_data["description"],
|
||||
is_active=rule_data["is_active"],
|
||||
)
|
||||
db.add(new_rule)
|
||||
await db.flush()
|
||||
logger.info(
|
||||
f"✅ Szabály létrehozva: {rule_data['action_key']} "
|
||||
f"(pont: {rule_data['points']}, ID: {new_rule.id})"
|
||||
)
|
||||
inserted_count += 1
|
||||
|
||||
await db.commit()
|
||||
logger.info(
|
||||
f"\n📊 Összegzés: {inserted_count} új szabály beszúrva, "
|
||||
f"{skipped_count} már létezett."
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
await db.rollback()
|
||||
logger.error(f"❌ Hiba a seedelés során: {e}", exc_info=True)
|
||||
raise
|
||||
finally:
|
||||
await engine.dispose()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(seed_provider_point_rules())
|
||||
Reference in New Issue
Block a user