Skip to content

TypeORM initialization errors and auth migration bug #1

@bl4ckh4nd

Description

@bl4ckh4nd

Description

The application is experiencing TypeORM initialization errors on startup and has a bug in the auth data migration.

Errors Observed

  1. TypeORM column errors during startup:

    • ❌ TypeORM get-requisitions failed, falling back: no such column: Requisition.requester_id
    • ❌ TypeORM get-purchase-orders failed, falling back: no such column: PurchaseOrder.order_number
  2. Auth migration bug:

    • File: src/main/database/migrations/auth-data-migration.ts
    • Line 351 references non-existent field: requisition.createdBy = requisition.requestedBy || adminUserId;
    • Should be: requisition.createdBy = requisition.requesterId || adminUserId;

Root Cause

  1. Initialization Order Issue: TypeORM is attempting to query tables before better-sqlite3 has created them during startup
  2. Migration Bug: The auth data migration references requestedBy but the Requisition entity only has requesterId

Impact

  • The application still works due to the hybrid architecture's automatic fallback mechanism
  • Error messages appear in logs but don't affect functionality
  • The fallback to better-sqlite3 ensures continued operation

Proposed Solutions

  1. Fix auth migration bug: Change requestedBy to requesterId in auth-data-migration.ts
  2. Fix initialization order: Ensure better-sqlite3 creates tables before TypeORM initialization
  3. Add existence check: Verify tables exist before TypeORM attempts queries

Technical Details

  • TypeORM entity mappings are correct (camelCase to snake_case)
  • Database schema definitions match entity mappings
  • The hybrid architecture's fallback mechanism prevents actual failures
  • Both requester_id and order_number columns exist in the schema

Steps to Reproduce

  1. Start the application with npm run dev
  2. Observe TypeORM errors in console during startup
  3. Note that application functions normally despite errors

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions