File size: 1,479 Bytes
27c8444
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
48
49
50
51
52
#!/usr/bin/env python3
"""
Migration script to add ConsumedSentence table for tracking used sentences.
Run this script once to update existing databases.
"""

import os
import sys
from flask import Flask
from models import db, ConsumedSentence

def create_app():
    app = Flask(__name__)
    app.config["SQLALCHEMY_DATABASE_URI"] = os.getenv(
        "DATABASE_URI", "sqlite:///tts_arena.db"
    )
    app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
    
    db.init_app(app)
    return app

def migrate():
    app = create_app()
    
    with app.app_context():
        try:
            # Create the ConsumedSentence table
            db.create_all()
            print("βœ… Successfully created ConsumedSentence table")
            
            # Check if table was created
            inspector = db.inspect(db.engine)
            tables = inspector.get_table_names()
            
            if 'consumed_sentence' in tables:
                print("βœ… ConsumedSentence table confirmed in database")
            else:
                print("❌ ConsumedSentence table not found after creation")
                
        except Exception as e:
            print(f"❌ Error during migration: {e}")
            return False
            
    return True

if __name__ == "__main__":
    print("Running ConsumedSentence table migration...")
    if migrate():
        print("Migration completed successfully!")
    else:
        print("Migration failed!")
        sys.exit(1)