File size: 1,280 Bytes
457b685
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env python
"""
Create translation tables in the database.
"""

import sys
import os
from pathlib import Path

# Add backend to path
backend_path = Path(__file__).parent
sys.path.insert(0, str(backend_path))

from src.database.base import engine, Base
from src.models import *  # Import all models

def create_tables():
    """Create all tables in the database."""
    try:
        # Import models to register them
        from src.models.auth import User
        from src.models.translation_openai import (
            TranslationJob, TranslationChunk, TranslationError,
            TranslationSession, TranslationCache, TranslationMetrics
        )

        # Create all tables
        Base.metadata.create_all(bind=engine)
        print("Translation tables created successfully!")

        # List created tables
        from sqlalchemy import inspect
        inspector = inspect(engine)
        tables = inspector.get_table_names()

        print("\nAvailable tables:")
        for table in sorted(tables):
            if 'translation' in table.lower():
                print(f"  - {table}")

    except Exception as e:
        print(f"Error creating tables: {e}")
        import traceback
        traceback.print_exc()

if __name__ == "__main__":
    create_tables()