Files
filwordspl-backend/reset_teacher_progress.py

79 lines
2.9 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""
Сброс прогресса учителя для ВСЕХ пользователей.
Очищает таблицы:
- user_learning_answers (все ответы)
- user_lesson_progress (прогресс уроков)
- user_topic_progress (прогресс тем)
- user_skill_mastery (мастерство)
- learning_sessions (сессии)
- teacher_chat_history (история чата учителя)
- teacher_ai_usage (AI-лимиты)
- ai_user_context (AI-контекст)
НЕ трогает: users, user_progress (филворды), sentence_progress, typing_progress,
word_quiz_progress, bubble_words_progress, user_achievements, daily_logins.
Запуск:
python3 reset_teacher_progress.py # спросит подтверждение
python3 reset_teacher_progress.py --force # без подтверждения
"""
import asyncio
import sys
import asyncpg
from config import DB_CONFIG
TABLES = [
"user_learning_answers",
"user_lesson_progress",
"user_topic_progress",
"user_skill_mastery",
"learning_sessions",
"teacher_chat_history",
"teacher_ai_usage",
"ai_user_context",
]
async def main():
pool = await asyncpg.create_pool(**DB_CONFIG)
async with pool.acquire() as conn:
total = 0
for table in TABLES:
try:
result = await conn.execute(f"DELETE FROM {table}")
affected = int(result.split()[-1])
total += affected
print(f"🗑️ {table}: удалено {affected}")
except Exception as e:
print(f"⚠️ {table}: {e}")
# Сбрасываем last_completed_level у всех (только для учителя)
# НЕ трогаем current_level — оставляем A1 у всех
result = await conn.execute(
"UPDATE users SET current_level = 'A1' WHERE current_level != 'A1'"
)
print(f"✅ users.current_level → A1")
await pool.close()
print(f"\n🎉 Готово! Удалено {total} записей.")
if __name__ == "__main__":
if len(sys.argv) < 2 or sys.argv[1] != "--force":
print("⚠️ ЭТОТ СКРИПТ УДАЛИТ ВЕСЬ ПРОГРЕСС УЧИТЕЛЯ У ВСЕХ ПОЛЬЗОВАТЕЛЕЙ!")
print(" Будут очищены: ответы, прогресс уроков, темы, мастерство, сессии,")
print(" история чата учителя, AI-лимиты.")
print("")
print(" НЕ трогает: users, филворды, предложения, печать, квиз, пузыри, достижения.")
print("")
confirm = input("Напиши YES для подтверждения: ")
if confirm != "YES":
print("❌ Отменено.")
sys.exit(0)
asyncio.run(main())