| """ |
| 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(): |
| |
| from auth.models import User |
| from history.models import ChatSession, ChatMessage |
|
|
| db.create_all() |
|
|