feat(backend): add database versioning

This commit is contained in:
2025-08-28 10:04:56 -04:00
parent 4df946731a
commit 954abb704e
6 changed files with 217 additions and 603 deletions

View File

@@ -44,16 +44,30 @@ def main():
if not args.command:
# Launch interactive mode when no command is provided
try:
cli = NimbusFlowCLI()
cli = NimbusFlowCLI(create_version=True) # Always create versioned DB for interactive mode
# Show versioning info with colors
from .base import Colors
versions = cli.list_database_versions()
if len(versions) > 1:
print(f"{Colors.CYAN}Database versions available:{Colors.RESET} {Colors.SUCCESS}{len(versions)}{Colors.RESET}")
print(f"{Colors.CYAN}Using:{Colors.RESET} {Colors.CYAN}{cli.db_path.name}{Colors.RESET}")
# Auto-cleanup if too many versions
if len(versions) > 10:
deleted = cli.cleanup_old_versions(keep_latest=5)
if deleted > 0:
print(f"{Colors.WARNING}Cleaned up {deleted} old database versions{Colors.RESET}")
run_interactive_mode(cli)
except CLIError as e:
print(f"❌ Error: {e}")
print(f"{Colors.ERROR}❌ Error: {e}{Colors.RESET}")
return 1
except KeyboardInterrupt:
print("\n🛑 Interrupted by user")
print(f"\n{Colors.WARNING}🛑 Interrupted by user{Colors.RESET}")
return 1
except Exception as e:
print(f"❌ Unexpected error: {e}")
print(f"{Colors.ERROR}❌ Unexpected error: {e}{Colors.RESET}")
return 1
finally:
if 'cli' in locals():
@@ -61,7 +75,11 @@ def main():
return
try:
cli = NimbusFlowCLI()
cli = NimbusFlowCLI(create_version=False) # Don't version for regular CLI commands
# Show which database is being used for regular commands
from .base import Colors
print(f"{Colors.CYAN}Using database:{Colors.RESET} {Colors.CYAN}{cli.db_path.name}{Colors.RESET}")
# Route commands to their respective handlers
if args.command == "members":
@@ -70,7 +88,7 @@ def main():
elif args.members_action == "show":
cmd_members_show(cli, args)
else:
print("❌ Unknown members action. Use 'list' or 'show'")
print(f"{Colors.ERROR}❌ Unknown members action. Use 'list' or 'show'{Colors.RESET}")
elif args.command == "schedules":
if args.schedules_action == "list":
@@ -84,25 +102,25 @@ def main():
elif args.schedules_action == "schedule":
cmd_schedules_schedule(cli, args)
else:
print("❌ Unknown schedules action. Use 'list', 'show', 'accept', 'decline', or 'schedule'")
print(f"{Colors.ERROR}❌ Unknown schedules action. Use 'list', 'show', 'accept', 'decline', or 'schedule'{Colors.RESET}")
elif args.command == "services":
if args.services_action == "list":
cmd_services_list(cli, args)
else:
print("❌ Unknown services action. Use 'list'")
print(f"{Colors.ERROR}❌ Unknown services action. Use 'list'{Colors.RESET}")
else:
print(f"❌ Unknown command: {args.command}")
print(f"{Colors.ERROR}❌ Unknown command: {args.command}{Colors.RESET}")
except CLIError as e:
print(f"❌ Error: {e}")
print(f"{Colors.ERROR}❌ Error: {e}{Colors.RESET}")
return 1
except KeyboardInterrupt:
print("\n🛑 Interrupted by user")
print(f"\n{Colors.WARNING}🛑 Interrupted by user{Colors.RESET}")
return 1
except Exception as e:
print(f"❌ Unexpected error: {e}")
print(f"{Colors.ERROR}❌ Unexpected error: {e}{Colors.RESET}")
return 1
finally:
if 'cli' in locals():