refactor: Improve error handling in create_trading_plan_table function

This commit is contained in:
Bobby (aider) 2025-02-11 18:01:35 -08:00
parent a22f4a444a
commit 2a790a164a

View File

@ -77,13 +77,11 @@ class TradingPlan:
def create_trading_plan_table(): def create_trading_plan_table():
"""Create the trading plans table if it doesn't exist""" """Create the trading plans table if it doesn't exist"""
with create_client() as client: with create_client() as client:
# First, try to drop the table if it exists
try: try:
# Drop the table if it exists to ensure a clean creation
client.execute("DROP TABLE IF EXISTS trading_plans") client.execute("DROP TABLE IF EXISTS trading_plans")
except Exception as e:
print(f"Error dropping table: {e}")
# Create new table with simpler structure # Create new table with a simple structure
query = """ query = """
CREATE TABLE IF NOT EXISTS trading_plans CREATE TABLE IF NOT EXISTS trading_plans
( (
@ -128,6 +126,10 @@ def create_trading_plan_table():
ENGINE = TinyLog ENGINE = TinyLog
""" """
client.execute(query) client.execute(query)
print("Table 'trading_plans' created successfully.")
except Exception as e:
print(f"Error creating table: {e}")
def save_trading_plan(plan: TradingPlan) -> int: def save_trading_plan(plan: TradingPlan) -> int:
"""Save a trading plan to the database""" """Save a trading plan to the database"""