File size: 672 Bytes
8a2dcce
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
"""
Shared SQLAlchemy instance.

Kept in its own module (rather than inside models.py or app.py) so that
every part of the application — auth, history, etc. — can import the same
`db` object without circular imports.
"""

from flask_sqlalchemy import SQLAlchemy

db = SQLAlchemy()


def init_db(app):
    """Bind SQLAlchemy to the Flask app and create tables if they don't exist."""
    db.init_app(app)
    with app.app_context():
        # Import models here so they're registered on db.metadata before create_all()
        from auth.models import User  # noqa: F401
        from history.models import ChatSession, ChatMessage  # noqa: F401

        db.create_all()