-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinit_db.py
More file actions
32 lines (26 loc) · 831 Bytes
/
init_db.py
File metadata and controls
32 lines (26 loc) · 831 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
31
32
# Description: This script is used to create the database tables.
# import
import os
import sys
from app import app
from models import db
# database file path
db_path = os.path.join("instance", "chatterbox.db")
# check if the force flag is provided
force = "-f" in sys.argv
# check if the database file exists and remove it
if os.path.exists(db_path):
if not force:
# ask the user for confirmation
print("Existing database will be REMOVED!")
confirmation = input("Do you want to continue? (y/n): ")
if confirmation.lower() != "y":
print("Operation cancelled")
exit()
# remove the database file
os.remove(db_path)
print("Database file removed")
# create the database tables
with app.app_context():
db.create_all()
print("Database tables created")