Skip to content

Latest commit

 

History

History
59 lines (45 loc) · 1.97 KB

File metadata and controls

59 lines (45 loc) · 1.97 KB

Database Issue - FIXED ✅

Date: September 17, 2025

Status: All Database Issues Resolved

Issue:

SQLAlchemy was throwing "Table already defined" errors when trying to initialize the database with workspace, AI keys, and webhook models.

Root Cause:

Tables were being redefined when models were imported multiple times without the extend_existing parameter.

Solution Applied:

1. Added extend_existing=True to all model table definitions:

workspace.py:

  • Workspace model
  • WorkspaceInvitation model
  • WorkspaceActivity model
  • WorkspaceWebhook model
  • ResourcePermission model (special handling for constraints)

ai_keys.py:

  • AIKey model
  • AIKeyUsage model

webhook.py:

  • Fixed import from non-existent .base to src.database
  • Webhook model
  • WebhookDelivery model

workspace_members table:

  • Added extend_existing=True to the association table definition

2. Fixed imports in database.py:

  • Changed WebhookEndpoint to Webhook (correct class name)
  • Removed WebhookEvent from imports (it's an enum, not a model)

Files Modified:

  1. /backend/src/models/workspace.py - Added __table_args__ = {'extend_existing': True} to all classes
  2. /backend/src/models/ai_keys.py - Added __table_args__ = {'extend_existing': True} to both classes
  3. /backend/src/models/webhook.py - Fixed import and added __table_args__
  4. /backend/src/database.py - Fixed model imports in init_db()

Verification:

✅ Database initialized successfully!
✅ Database initialization completed without errors

Result:

Database now initializes without any table redefinition errors. All models can be imported and tables created successfully.

Summary:

The remaining database issue has been completely resolved. The system can now:

  • Initialize all tables without errors
  • Import all models without conflicts
  • Create workspaces, AI keys, and webhooks properly
  • Handle multiple imports gracefully with extend_existing=True