SIDEL_ScriptsManager/check_tables.py

59 lines
1.7 KiB
Python

#!/usr/bin/env python3
"""
Check and create missing database tables
"""
import sys
import os
sys.path.append(".")
from app.config.database import init_db
from app.models import CondaEnvironment, UserProject, UserScriptTag, ExecutionLog
from flask import Flask
def check_tables():
app = Flask(__name__)
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///data/scriptsmanager.db"
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
with app.app_context():
db = init_db(app)
# Create all tables
print("Creating missing tables...")
db.create_all()
# Check if conda environments table exists and has data
try:
conda_envs = CondaEnvironment.query.all()
print(f"Found {len(conda_envs)} conda environments in database")
for env in conda_envs:
print(f" - {env.name}: {env.python_version} ({env.path})")
except Exception as e:
print(f"Error checking conda environments: {e}")
# Check other tables
try:
projects = UserProject.query.all()
print(f"Found {len(projects)} user projects")
except Exception as e:
print(f"Error checking user projects: {e}")
try:
tags = UserScriptTag.query.all()
print(f"Found {len(tags)} user script tags")
except Exception as e:
print(f"Error checking user script tags: {e}")
try:
logs = ExecutionLog.query.all()
print(f"Found {len(logs)} execution logs")
except Exception as e:
print(f"Error checking execution logs: {e}")
if __name__ == "__main__":
check_tables()