|
from sqlalchemy import create_engine, MetaData, inspect |
|
|
|
|
|
engine = create_engine("sqlite:///database.db") |
|
metadata_obj = MetaData() |
|
|
|
|
|
def get_existing_tables(): |
|
""" |
|
Returns a list of existing tables in the database. |
|
|
|
Returns: |
|
list: List of table names. |
|
""" |
|
inspector = inspect(engine) |
|
return inspector.get_table_names() |
|
|
|
|
|
def initialize_database(): |
|
""" |
|
Checks if database is empty and prompts user to upload an SQL file if needed. |
|
""" |
|
tables = get_existing_tables() |
|
if not tables: |
|
print("No tables found in the database. Please upload an SQL file.") |
|
else: |
|
print(f"Database initialized with tables: {tables}") |
|
|
|
initialize_database() |
|
|
|
|