-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathreset_db.py
More file actions
30 lines (25 loc) · 868 Bytes
/
reset_db.py
File metadata and controls
30 lines (25 loc) · 868 Bytes
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
import os
from src.app import create_app
from src.models import db
def reset_database():
app = create_app()
with app.app_context():
print("dropping all existing tables...")
db.drop_all()
print("creating all tables w correct struct...")
db.create_all()
print(" +++++ DB RESET COMPLETED +++++ ")
from src.models import User, Account, Transaction, Loan
try:
ucnt = User.query.count()
accnt = Account.query.count()
trcnt = Transaction.query.count()
lcnt = Loan.query.count()
print(f" -- Users table: {ucnt} records")
print(f" -- Accounts table: {accnt} records")
print(f" -- Transactions table: {trcnt} records")
print(f" -- Loans table: {lcnt} records")
print("\n +++ ALL TABLES CREATED SUCCESSFULLY +++ ")
except Exception as e: print(f" !!! ERR VERIFYING TABLES -- {e} !!!")
if __name__ == '__main__':
reset_database()