Spaces:
Sleeping
Sleeping
Update database.py
Browse files- database.py +3 -1
database.py
CHANGED
@@ -6,15 +6,17 @@ metadata_obj = MetaData()
|
|
6 |
|
7 |
# Function to check existing tables
|
8 |
def get_existing_tables():
|
|
|
9 |
inspector = inspect(engine)
|
10 |
return inspector.get_table_names()
|
11 |
|
12 |
# Function to initialize database if empty
|
13 |
def initialize_database():
|
|
|
14 |
tables = get_existing_tables()
|
15 |
if not tables:
|
16 |
print("No tables found in the database. Please upload an SQL file.")
|
17 |
else:
|
18 |
print(f"Database initialized with tables: {tables}")
|
19 |
|
20 |
-
initialize_database()
|
|
|
6 |
|
7 |
# Function to check existing tables
|
8 |
def get_existing_tables():
|
9 |
+
"""Returns a list of existing tables in the database."""
|
10 |
inspector = inspect(engine)
|
11 |
return inspector.get_table_names()
|
12 |
|
13 |
# Function to initialize database if empty
|
14 |
def initialize_database():
|
15 |
+
"""Checks if database is empty and prompts user to upload an SQL file if needed."""
|
16 |
tables = get_existing_tables()
|
17 |
if not tables:
|
18 |
print("No tables found in the database. Please upload an SQL file.")
|
19 |
else:
|
20 |
print(f"Database initialized with tables: {tables}")
|
21 |
|
22 |
+
initialize_database()
|