Spaces:
Sleeping
Sleeping
| """ | |
| Script para crear la tabla 'actions' en la base de datos remota | |
| """ | |
| import mysql.connector | |
| from dotenv import load_dotenv | |
| import os | |
| # Cargar variables de entorno | |
| load_dotenv() | |
| try: | |
| # Conexión a la base de datos | |
| conexion = mysql.connector.connect( | |
| host=os.getenv('DB_HOST'), | |
| user=os.getenv('DB_USER'), | |
| password=os.getenv('mariadb_c'), | |
| database=os.getenv('DB_NAME'), | |
| port=int(os.getenv('DB_PORT', 3306)), | |
| autocommit=True | |
| ) | |
| cursor = conexion.cursor() | |
| # Verificar si la tabla ya existe | |
| cursor.execute(""" | |
| SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES | |
| WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'action_call' | |
| """) | |
| if cursor.fetchone(): | |
| print("ℹ️ La tabla 'action_call' ya existe") | |
| else: | |
| # Crear la tabla | |
| cursor.execute(""" | |
| CREATE TABLE `action_call` ( | |
| `usuario` varchar(255) PRIMARY KEY, | |
| `uid` varchar(255), | |
| `displayName` varchar(255), | |
| `email` varchar(255), | |
| `action_call` boolean, | |
| `country_header` varchar(10), | |
| `country_ip` varchar(10), | |
| `creditos` int, | |
| `esta_hora` int, | |
| `explicit_counter` int, | |
| `fecha_registro` datetime, | |
| `gaClient` varchar(255), | |
| `open_use` boolean, | |
| `ritmo` decimal(10,2), | |
| `streak` int, | |
| `ultima_generacion_hora` datetime, | |
| `ultimo_uso` datetime, | |
| `usos` int, | |
| `created_at` timestamp DEFAULT CURRENT_TIMESTAMP, | |
| `updated_at` timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP | |
| ) | |
| """) | |
| print("✅ Tabla 'actions' creada correctamente") | |
| # Mostrar estructura | |
| cursor.execute("DESCRIBE actions") | |
| columnas = cursor.fetchall() | |
| print("\n📋 Estructura de la tabla 'actions':") | |
| for col in columnas: | |
| print(f" - {col[0]}: {col[1]}") | |
| cursor.close() | |
| conexion.close() | |
| except Exception as e: | |
| print(f"❌ Error: {str(e)}") | |