File size: 812 Bytes
d4bd626
 
a400f6e
d4bd626
 
add59ac
d4bd626
 
 
a400f6e
037ba4c
c5cf00a
d4bd626
add59ac
d4bd626
 
 
a400f6e
d4bd626
 
a400f6e
d4bd626
 
a400f6e
d4bd626
a400f6e
d4bd626
 
 
 
a400f6e
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
from sqlalchemy import create_engine, MetaData, inspect

# Initialize the SQLite database
engine = create_engine("sqlite:///database.db")
metadata_obj = MetaData()

# Function to check existing tables
def get_existing_tables():
    """
    Returns a list of tables currently in the database.

    Returns:
        list: List of table names.
    """
    inspector = inspect(engine)
    return inspector.get_table_names()

# Function to safely start the database
def initialize_database():
    """
    Starts the database without failing if no SQL file is uploaded yet.
    """
    tables = get_existing_tables()
    
    if not tables:
        print("No tables found. The database is waiting for an SQL file upload.")
    else:
        print(f"Database initialized with tables: {tables}")

initialize_database()