mirror of
https://github.com/StefBuwalda/dashboard_test.git
synced 2025-10-29 18:59:59 +00:00
23 lines
567 B
Python
23 lines
567 B
Python
from flask_sqlalchemy import SQLAlchemy
|
|
from flask_migrate import Migrate, upgrade, stamp
|
|
from .flask_app import app
|
|
from pathlib import Path
|
|
|
|
__all__ = ["app"]
|
|
|
|
# Create db
|
|
db = SQLAlchemy(app=app)
|
|
|
|
# Set up migration
|
|
migrations_dir = Path(__file__).parent / "migrations"
|
|
migration = Migrate(app=app, db=db, directory=str(migrations_dir))
|
|
|
|
# Init and upgrade
|
|
with app.app_context():
|
|
# Check if DB file is missing
|
|
if not (Path("./instance/app.db").is_file()):
|
|
db.create_all()
|
|
stamp()
|
|
# Upgrade db if any new migrations exist
|
|
upgrade()
|