Spaces:
Sleeping
Sleeping
| #!/usr/bin/env python3 | |
| """ | |
| Deploy local database to production environment. | |
| This script copies the local SQLite database to the production location. | |
| """ | |
| import os | |
| import shutil | |
| import sys | |
| def main(): | |
| """Copy local database to production location""" | |
| # Get the current directory (this will be /app in production) | |
| base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | |
| local_db = os.path.join(base_dir, "users.db") | |
| print(f"Database location: {local_db}") | |
| # Check if database exists | |
| if not os.path.exists(local_db): | |
| print(f"Error: Database not found at {local_db}") | |
| return 1 | |
| # Get database info | |
| size = os.path.getsize(local_db) | |
| print(f"Database size: {size} bytes") | |
| # Verify database structure | |
| import sqlite3 | |
| try: | |
| conn = sqlite3.connect(local_db) | |
| cursor = conn.cursor() | |
| # Check tables | |
| cursor.execute("SELECT name FROM sqlite_master WHERE type='table';") | |
| tables = cursor.fetchall() | |
| print(f"Tables found: {[table[0] for table in tables]}") | |
| # Check user count | |
| cursor.execute("SELECT COUNT(*) FROM users") | |
| user_count = cursor.fetchone()[0] | |
| print(f"Users in database: {user_count}") | |
| # Check prediction count | |
| cursor.execute("SELECT COUNT(*) FROM predictions") | |
| prediction_count = cursor.fetchone()[0] | |
| print(f"Predictions in database: {prediction_count}") | |
| conn.close() | |
| print("Database verification successful!") | |
| return 0 | |
| except Exception as e: | |
| print(f"Error verifying database: {e}") | |
| return 1 | |
| if __name__ == "__main__": | |
| sys.exit(main()) | |