-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit_db.py
31 lines (25 loc) · 825 Bytes
/
init_db.py
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
from sqlalchemy import MetaData
import os
from app import db
from app import app
from models.fin_user import FinUser
from models.transaction import Transaction
def delete_existing_database():
db_file = 'finhandle.db' # Your database filename
if os.path.exists(db_file):
os.remove(db_file)
print("Existing database file deleted.")
else:
print("No existing database file found.")
# init_db.py
def create_tables():
with app.app_context():
db.create_all()
print("Database tables created.")
meta = MetaData()
meta.reflect(bind=db.engine)
print("Existing tables:", meta.tables.keys()) # Print the list of table names in the database
if __name__ == '__main__':
delete_existing_database()
with app.app_context():
create_tables()