Spaces:
Sleeping
Sleeping
| """ | |
| Скрипт для полной очистки и повторной вставки объектов с правильным admin user | |
| """ | |
| import psycopg2 | |
| DB_CONFIG = { | |
| 'host': 'dpg-d5ht8vi4d50c739akh2g-a.virginia-postgres.render.com', | |
| 'port': 5432, | |
| 'database': 'lead_exchange_bk', | |
| 'user': 'lead_exchange_bk_user', | |
| 'password': '8m2gtTRBW0iAr7nY2Aadzz0VcZBEVKYM' | |
| } | |
| print("=" * 70) | |
| print("CLEANUP AND VERIFICATION") | |
| print("=" * 70) | |
| try: | |
| conn = psycopg2.connect(**DB_CONFIG) | |
| cursor = conn.cursor() | |
| # Показываем текущее состояние | |
| cursor.execute("SELECT COUNT(*) FROM properties") | |
| current_count = cursor.fetchone()[0] | |
| print(f"\n📊 Current properties count: {current_count}") | |
| # Показываем всех админов | |
| cursor.execute(""" | |
| SELECT user_id, email, first_name, last_name, created_at | |
| FROM users | |
| WHERE role = 'ADMIN' | |
| ORDER BY created_at DESC | |
| """) | |
| admins = cursor.fetchall() | |
| print(f"\n👥 Admin users in database:") | |
| for user_id, email, first_name, last_name, created in admins: | |
| print(f" - {email}") | |
| print(f" Name: {first_name} {last_name}") | |
| print(f" ID: {user_id}") | |
| print(f" Created: {created}") | |
| # Проверяем сколько properties у этого админа | |
| cursor.execute("SELECT COUNT(*) FROM properties WHERE owner_user_id = %s", (user_id,)) | |
| prop_count = cursor.fetchone()[0] | |
| print(f" Properties: {prop_count}") | |
| print() | |
| # Удаляем все properties | |
| print("🗑️ Deleting all properties...") | |
| cursor.execute("DELETE FROM properties") | |
| conn.commit() | |
| print("✅ All properties deleted") | |
| # Проверяем | |
| cursor.execute("SELECT COUNT(*) FROM properties") | |
| final_count = cursor.fetchone()[0] | |
| print(f"📊 Properties after cleanup: {final_count}") | |
| print("\n" + "=" * 70) | |
| print("✅ Ready for fresh insert!") | |
| print("Run: python add_properties.py --yes") | |
| print("=" * 70) | |
| cursor.close() | |
| conn.close() | |
| except Exception as e: | |
| print(f"❌ Error: {e}") | |
| import traceback | |
| traceback.print_exc() | |