the_works/the_works/database.py

19 lines
561 B
Python

from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy()
def init_db(app):
db.init_app(app)
with app.app_context():
print(f"number of db tables is {len(db.metadata.tables)}")
# populate an empty DB with fresh tables
#TODO: maybe add tables to metadata in any case since tables won't get overwritten
if not len(db.metadata.tables):
from the_works.tables import add_tables
add_tables(db.metadata)
db.metadata.create_all(db.engine)
print(f"and now number of db tables is {len(db.metadata.tables)}")
db.reflect()