# reset_erp_db.py import os import pathlib from data.utils.erp_db_init import init_sqlite_db from data.utils.populate_erp_db import populate_erp_db def reset_erp_db(db_path='./data/erp_db.sqlite'): """Reset the ERP database by deleting it and recreating it with fresh data.""" try: print(f"Resetting ERP database at {db_path}...") # Check if database file exists if os.path.exists(db_path): print(f"Removing existing database file...") os.remove(db_path) print(f"Database file removed.") else: print(f"No existing database file found.") # Create database directory if it doesn't exist db_dir = pathlib.Path(os.path.dirname(db_path)) db_dir.mkdir(exist_ok=True) # Initialize the database print(f"Initializing new database...") init_result = init_sqlite_db(db_path) if not init_result: print(f"Failed to initialize database.") return False print(f"Database initialized successfully.") # Populate the database with sample data print(f"Populating database with sample data...") populate_result = populate_erp_db(db_path) if not populate_result: print(f"Failed to populate database.") return False print(f"Database populated successfully.") print(f"Database reset complete.") return True except Exception as e: print(f"Error resetting database: {str(e)}") return False if __name__ == "__main__": reset_erp_db()